2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/op/arithmetics.t - Arithmetic Ops
11 % prove t/op/arithmetics.t
15 Tests basic arithmetic on various combinations of Parrot integer and
21 .include 'test_more.pir'
22 .include 'iglobals.pasm'
26 take_the_negative_of_a_native_integer()
27 take_the_absolute_of_a_native_integer()
28 add_native_integer_to_native_integer()
29 subtract_native_integer_from_native_integer()
30 multiply_native_integer_with_native_integer()
31 divide_native_integer_by_native_integer()
32 negate_minus_zero_point_zero()
33 negate_a_native_number()
34 take_the_absolute_of_a_native_number()
35 ceil_of_a_native_number()
36 floor_of_a_native_number()
37 add_native_integer_to_native_number()
38 subtract_native_integer_from_native_number()
39 multiply_native_number_with_native_integer()
40 divide_native_number_by_native_integer()
41 add_native_number_to_native_number()
42 subtract_native_number_from_native_number()
43 multiply_native_number_with_native_number()
44 divide_native_number_by_native_number()
50 # Operations on a single INTVAL
52 .sub take_the_negative_of_a_native_integer
55 is( $I0, "0", 'take_the_negative_of_a_native_integer' )
59 is( $I0, "-1234567890", 'take_the_negative_of_a_native_integer' )
63 is( $I0, "1234567890", 'take_the_negative_of_a_native_integer' )
68 is( $I1, "0", 'take_the_negative_of_a_native_integer' )
72 is( $I1, "-1234567890", 'take_the_negative_of_a_native_integer' )
76 is( $I1, "1234567890", 'take_the_negative_of_a_native_integer' )
79 .sub take_the_absolute_of_a_native_integer
82 is( $I0, "0", 'take_the_absolute_of_a_native_integer' )
86 is( $I0, "1234567890", 'take_the_absolute_of_a_native_integer' )
90 is( $I0, "1234567890", 'take_the_absolute_of_a_native_integer' )
95 is( $I1, "0", 'take_the_absolute_of_a_native_integer' )
99 is( $I1, "1234567890", 'take_the_absolute_of_a_native_integer' )
103 is( $I1, "1234567890", 'take_the_absolute_of_a_native_integer' )
107 # first arg is INTVAL, second arg is INTVAL
109 .sub add_native_integer_to_native_integer
113 is( $I2, "3877", 'add_native_integer_to_native_integer' )
116 is( $I0, "3877", 'add_native_integer_to_native_integer' )
119 .sub subtract_native_integer_from_native_integer
123 is( $I2, "4123", 'subtract_native_integer_from_native_integer' )
126 is( $I0, "4123", 'subtract_native_integer_from_native_integer' )
129 .sub multiply_native_integer_with_native_integer
133 is( $I2, "-492000", 'multiply_native_integer_with_native_integer' )
136 is( $I0, "-492000", 'multiply_native_integer_with_native_integer' )
139 .sub divide_native_integer_by_native_integer
143 is( $I2, "-32", 'divide_native_integer_by_native_integer' )
146 is( $I0, "-32", 'divide_native_integer_by_native_integer' )
152 .sub negate_minus_zero_point_zero
153 .local pmc interp, config_hash
154 .local string has_negative_zero
156 config_hash = interp[.IGLOBALS_CONFIG_HASH]
157 has_negative_zero = config_hash['has_negative_zero']
162 unless has_negative_zero goto Todo_test1
167 todo($I0, 'negative zero, TT #313')
184 unless has_negative_zero goto Todo_test4
189 todo($I0, 'negative zero, TT #313')
194 # Operations on a single NUMVAL
196 .sub negate_a_native_number
199 is( $N0, "-123.456789", 'negate_a_native_number' )
201 set $N0, -123.4567890
203 is( $N0, "123.456789", 'negate_a_native_number' )
207 is( $N1, "-123.456789", 'negate_a_native_number' )
209 set $N0, -123.4567890
211 is( $N1, "123.456789", 'negate_a_native_number' )
214 .sub take_the_absolute_of_a_native_number
217 is( $N0, "0", 'take_the_absolute_of_a_native_number' )
221 is( $N0, "0", 'take_the_absolute_of_a_native_number' )
223 set $N0, 123.45678901
225 is( $N0, "123.45678901", 'take_the_absolute_of_a_native_number' )
227 set $N0, -123.45678901
229 is( $N0, "123.45678901", 'take_the_absolute_of_a_native_number' )
234 is( $N1, "0", 'take_the_absolute_of_a_native_number' )
239 is( $N1, "0", 'take_the_absolute_of_a_native_number' )
241 set $N0, 123.45678901
244 is( $N1, "123.45678901", 'take_the_absolute_of_a_native_number' )
246 set $N0, -123.45678901
249 is( $N1, "123.45678901", 'take_the_absolute_of_a_native_number' )
252 .sub ceil_of_a_native_number
255 is( $N0, "0", 'ceil_of_a_native_number' )
257 set $N0, 123.45678901
259 is( $N0, "124", 'ceil_of_a_native_number' )
261 set $N0, -123.45678901
263 is( $N0, "-123", 'ceil_of_a_native_number' )
268 is( $N1, "0", 'ceil_of_a_native_number' )
273 is( $N1, "0", 'ceil_of_a_native_number' )
275 set $N0, 123.45678901
278 is( $N1, "124", 'ceil_of_a_native_number' )
280 set $N0, -123.45678901
283 is( $N1, "-123", 'ceil_of_a_native_number' )
288 is( $I1, "0", 'ceil_of_a_native_number' )
293 is( $I1, "0", 'ceil_of_a_native_number' )
295 set $N0, 123.45678901
298 is( $I1, "124", 'ceil_of_a_native_number' )
300 set $N0, -123.45678901
303 is( $I1, "-123", 'ceil_of_a_native_number' )
306 .sub floor_of_a_native_number
309 is( $N0, "0", 'floor_of_a_native_number' )
311 set $N0, 123.45678901
313 is( $N0, "123", 'floor_of_a_native_number' )
315 set $N0, -123.45678901
317 is( $N0, "-124", 'floor_of_a_native_number' )
322 is( $N1, "0", 'floor_of_a_native_number' )
327 is( $N1, "0", 'floor_of_a_native_number' )
329 set $N0, 123.45678901
332 is( $N1, "123", 'floor_of_a_native_number' )
334 set $N0, -123.45678901
337 is( $N1, "-124", 'floor_of_a_native_number' )
342 is( $I1, "0", 'floor_of_a_native_number' )
347 is( $I1, "0", 'floor_of_a_native_number' )
349 set $N0, 123.45678901
352 is( $I1, "123", 'floor_of_a_native_number' )
354 set $N0, -123.45678901
357 is( $I1, "-124", 'floor_of_a_native_number' )
362 # FLOATVAL and INTVAL tests
364 .sub add_native_integer_to_native_number
368 is( $N1, "3876.877", 'add_native_integer_to_native_number' )
371 is( $N0, "3876.877", 'add_native_integer_to_native_number' )
374 is( $N0, "7876.877", 'add_native_integer_to_native_number' )
378 .sub subtract_native_integer_from_native_number
382 is( $N1, "-4123.123", 'subtract_native_integer_from_native_number' )
385 is( $N0, "-4123.123", 'subtract_native_integer_from_native_number' )
388 is( $N0, "-8123.123", 'subtract_native_integer_from_native_number' )
392 .sub multiply_native_number_with_native_integer
396 is( $N1, "-492492", 'multiply_native_number_with_native_integer' )
399 is( $N0, "-492492", 'multiply_native_number_with_native_integer' )
402 is( $N0, "984984", 'multiply_native_number_with_native_integer' )
405 .sub divide_native_number_by_native_integer
409 is( $N1, "-0.03078075", 'divide_native_number_by_native_integer' )
412 is( $N0, "-0.03078075", 'divide_native_number_by_native_integer' )
415 is( $N0, "-0.03078075", 'divide_native_number_by_native_integer' )
419 is( $N0, "1", 'divide_native_number_by_native_integer' )
422 is( $N0, "100", 'divide_native_number_by_native_integer' )
426 # FLOATVAL and FLOATVAL tests
428 .sub add_native_number_to_native_number
432 is( $N1, "3877.123", 'add_native_number_to_native_number' )
435 is( $N0, "3877.123", 'add_native_number_to_native_number' )
438 .sub subtract_native_number_from_native_number
442 is( $N1, "-4123.369", 'subtract_native_number_from_native_number' )
445 is( $N0, "-4123.369", 'subtract_native_number_from_native_number' )
449 .sub multiply_native_number_with_native_number
453 is( $N1, "-492522.288258", 'multiply_native_number_with_native_number' )
456 is( $N0, "-492522.288258", 'multiply_native_number_with_native_number' )
460 .sub divide_native_number_by_native_number
464 is( $N1, "-0.0307788571002883", 'divide_native_number_by_native_number' )
467 is( $N0, "-0.0307788571002883", 'divide_native_number_by_native_number' )
475 # vim: expandtab shiftwidth=4 ft=pir: