1 # Copyright (C) 2006-2008, The Perl Foundation.
6 runtime/wmlsfloat.pir - WMLScript Float library
10 This library contains a set of typical arithmetic floating-point functions that
11 are frequently used by applications.
13 See "WMLScript Standard Libraries Specification", section 8 "Float".
20 .HLL 'WMLScript', 'wmls_group'
26 .const .Sub _float_int = '_float_int'
28 .const .Sub _float_floor = '_float_floor'
30 .const .Sub _float_ceil = '_float_ceil'
32 .const .Sub _float_pow = '_float_pow'
34 .const .Sub _float_round = '_float_round'
36 .const .Sub _float_sqrt = '_float_sqrt'
38 .const .Sub _float_maxFloat = '_float_maxFloat'
39 $P0[6] = _float_maxFloat
40 .const .Sub _float_minFloat = '_float_minFloat'
41 $P0[7] = _float_minFloat
51 Returns the integer part of the given value. If the value is already an integer,
52 the result is the value itself.
64 .sub '_float_int' :anon
68 $I0 = isa value, 'WmlsString'
70 $P0 = value.'parseNumber'()
72 $I0 = isa $P0, 'WmlsInvalid'
75 new res, 'WmlsInteger'
79 new res, 'WmlsInvalid'
85 =head2 C<floor(value)>
89 Returns the greatest integer value that is not greater than the given value. If
90 the value is already an integer, the result is the value itself.
102 .sub '_float_floor' :anon
106 $I0 = isa value, 'WmlsString'
108 $P0 = value.'parseNumber'()
110 $I0 = isa $P0, 'WmlsInvalid'
114 new res, 'WmlsInteger'
118 new res, 'WmlsInvalid'
124 =head2 C<ceil(value)>
128 Returns the smallest integer value that is not less than the given value. If
129 the value is already an integer, the result is the value itself.
141 .sub '_float_ceil' :anon
145 $I0 = isa value, 'WmlsString'
147 $P0 = value.'parseNumber'()
149 $I0 = isa $P0, 'WmlsInvalid'
153 new res, 'WmlsInteger'
157 new res, 'WmlsInvalid'
163 =head2 C<pow(value1, value2)>
167 Returns an implementation-dependent approximation to the result of raising
168 value1 to the power of value2. If value1 is a negative number then value2
179 Floating-point or invalid.
183 If value1 == 0 and value2 < 0 then C<invalid> is returned.
185 If value1 < 0 and value2 is not an integer then C<invalid> is returned.
189 .sub '_float_pow' :anon
194 $I0 = isa value1, 'WmlsString'
196 $P1 = value1.'parseNumber'()
198 $I0 = isa $P1, 'WmlsInvalid'
202 $I0 = isa value2, 'WmlsString'
204 $P2 = value2.'parseNumber'()
206 $I0 = isa $P2, 'WmlsInvalid'
209 unless $N1 == 0.0 goto L4
215 unless $N1 < 0.0 goto L6
216 $I0 = isa $P2, 'WmlsFloat'
224 new res, 'WmlsInvalid'
230 =head2 C<round(value)>
234 Returns the number value that is closest to the given value and is equal to a
235 mathematical integer. If two integer number values are equally close to the
236 value, the result is the larger number value. If the value is already an
237 integer, the result is the value itself.
249 .sub '_float_round' :anon
253 $I0 = isa value, 'WmlsString'
255 $P0 = value.'parseNumber'()
257 $I0 = isa $P0, 'WmlsInvalid'
262 new res, 'WmlsInteger'
266 new res, 'WmlsInvalid'
272 =head2 C<sqrt(value)>
276 Returns an implementation-dependent approximation to the square root of
281 value = Floating-point
285 Floating-point or invalid.
289 If value is a negative number then invalid is returned.
293 .sub '_float_sqrt' :anon
297 $I0 = isa value, 'WmlsString'
299 $P0 = value.'parseNumber'()
301 $I0 = isa $P0, 'WmlsInvalid'
310 new res, 'WmlsInvalid'
320 Returns the maximum floating-point value supported by [IEEE754] single
321 precision floating-point format.
325 Floating-point 3.40282347e+38.
329 .sub '_float_maxFloat' :anon
332 set res, 3.40282347e+38
341 Returns the smallest nonzero floating-point value supported by [IEEE754]
342 single precision floating-point format.
346 Floating-point. Smaller than or equal to the normalised minimum single
347 precision floating-point value: 1.17549435e-38.
351 .sub '_float_minFloat' :anon
354 set res, 1.17549435e-38
370 # vim: expandtab shiftwidth=4 ft=pir: