Ticket #969: float.t_to_pir.patch
File float.t_to_pir.patch, 48.9 KB (added by flh, 6 years ago) 


t/pmc/float.t
1 #! perl1 #! parrot 2 2 # Copyright (C) 20012009, Parrot Foundation. 3 3 # $Id$ 4 4 5 use strict;6 use warnings;7 use lib qw( . lib ../lib ../../lib );8 9 use Test::More;10 use Parrot::Test tests => 61;11 use Parrot::Config;12 13 5 =head1 NAME 14 6 15 7 t/pmc/float.t  Floatingpoint Numbers … … 24 16 25 17 =cut 26 18 19 .const int TESTS = 159 20 .const num PRECISION = 0.000001 27 21 28 pasm_output_is( <<"CODE", <<OUTPUT, "basic assignment" ); 29 .include 'fp_equality.pasm' 30 new P0, ['Float'] 22 .sub 'test' :main 23 .include 'test_more.pir' 31 24 32 set P0, 0.001 33 .fp_eq_pasm( P0, 0.001, EQ1) 34 print "not " 35 EQ1: print "ok 1\\n" 25 plan(TESTS) 26 basic_assignment() 27 add_number_to_self() 28 sub_number_from_self() 29 multiply_number_by_self() 30 divide_number_by_self() 31 divide_by_zero() 32 truth_positive_float() 33 truth_negative_float() 34 truth_positive_integer() 35 truth_negative_integer() 36 falseness_0() 37 'falseness_0.000'() 38 integer_addition() 39 integer_substraction() 40 integer_multiplication() 41 integer_division() 42 number_addition() 43 number_substraction() 44 number_multiplication() 45 number_division() 46 increment_decrement() 47 'neg'() 48 negative_zero() 49 equality() 50 is_interface_done() 51 'abs'() 52 'lt'() 53 'lt_num'() 54 'le'() 55 'le_num'() 56 'gt'() 57 'gt_num'() 58 'ge'() 59 'ge_num'() 60 cmp_p_n() 61 'isgt'() 62 'isge'() 63 'islt'() 64 'isle'() 65 'iseq'() 66 'isne'() 67 instantiate_str() 68 cmp_subclasses() 69 acos_method() 70 cos_method() 71 asec_method() 72 asin_method() 73 atan_method() 74 atan2_method() 75 cosh_method() 76 exp_method() 77 ln_method() 78 log10_method() 79 log2_method() 80 sec_method() 81 sech_method() 82 sin_method() 83 sinh_method() 84 tan_method() 85 tanh_method() 86 sqrt_method() 87 .end 36 88 37 set P0, 1000 38 .fp_eq_pasm( P0, 1000.0, EQ2) 39 print "not " 40 EQ2: print "ok 2\\n" 89 .include 'fp_equality.pasm' 41 90 42 set P0, "12.5" 43 .fp_eq_pasm( P0, 12.5, EQ3) 44 print "not " 45 EQ3: print "ok 3\\n" 91 .sub 'basic_assignment' 92 $P0 = new ['Float'] 46 93 47 set P0, "Twelve point five" 48 .fp_eq_pasm( P0, 0.0, EQ4) 49 print "not " 50 EQ4: print "ok 4\\n" 94 $P0 = 0.001 95 is($P0, 0.001, 'basic float assignment 1', PRECISION) 51 96 52 set P0, 123.45 53 set I0, P0 54 eq I0, 123, EQ5 55 print "not " 56 EQ5: print "ok 5\\n" 97 $P0 = 12.5 98 is($P0, 12.5, 'basic assignment 2', PRECISION) 57 99 58 set P0, 123.45 59 set N0, P0 60 .fp_eq_pasm(N0, 123.45, EQ6) 61 print "not " 62 EQ6: print "ok 6\\n" 100 $P0 = 1000 101 is($P0, 1000.0, 'basic integer assignment', PRECISION) 63 102 64 set P0, 123.45 65 set S0, P0 66 eq S0, "123.45", EQ7 67 print "not " 68 EQ7: print "ok 7\\n" 103 $P0 = 'Twelve point five' 104 is($P0, 0.0, 'basic string assignment', PRECISION) 69 105 70 end 71 CODE 72 ok 1 73 ok 2 74 ok 3 75 ok 4 76 ok 5 77 ok 6 78 ok 7 79 OUTPUT 106 $P0 = 123.45 107 $I0 = $P0 108 is($I0, 123, 'rounding to integer') 80 109 81 pasm_output_is( <<"CODE", <<OUTPUT, "add number to self" ); 82 .include 'fp_equality.pasm' 83 new P0, ['Float'] 84 set P0, 0.001 85 add P0, P0, P0 86 .fp_eq_pasm( P0, 0.002, EQ1) 87 print P0 88 print "not " 89 EQ1: print "ok 1\\n" 90 end 91 CODE 92 ok 1 93 OUTPUT 110 $P0 = 123.45 111 $N0 = $P0 112 is($N0, 123.45, 'get_float_value', PRECISION) 94 113 95 pasm_output_is( <<"CODE", <<OUTPUT, "sub number from self" ); 96 .include 'fp_equality.pasm' 97 new P0, ['Float'] 98 set P0, 1000.2 99 sub P0, P0, P0 100 .fp_eq_pasm( P0, 0.0, EQ1) 101 print P0 102 print "not " 103 EQ1: print "ok 1\\n" 104 end 105 CODE 106 ok 1 107 OUTPUT 114 $P0 = 123.45 115 $S0 = $P0 116 is($S0, '123.45', 'get string') 108 117 109 pasm_output_is( <<"CODE", <<OUTPUT, "multiply number by self" ); 110 .include 'fp_equality.pasm' 111 new P0, ['Float'] 112 set P0, 123.4 113 mul P0, P0, P0 114 .fp_eq_pasm( P0, 15227.56, EQ1) 115 print P0 116 print "not " 117 EQ1: print "ok 1\\n" 118 end 119 CODE 120 ok 1 121 OUTPUT 118 $P0 = "12.49" 119 $P1 = get_class ['Float'] 120 is($P0, 12.49, 'setting value from string', PRECISION) 121 .end 122 122 123 pasm_output_is( <<"CODE", <<OUTPUT, "divide number by self" ); 124 .include 'fp_equality.pasm' 125 new P0, ['Float'] 126 set P0, 1829354.988 127 div P0, P0, P0 128 .fp_eq_pasm( P0, 1.0, EQ1) 129 print P0 130 print "not " 131 EQ1: print "ok 1\\n" 132 end 133 CODE 134 ok 1 135 OUTPUT 123 .sub 'add_number_to_self' 124 $P0 = new ['Float'] 125 $P0 = 0.001 126 $P0 = $P0 + $P0 136 127 137 pir_output_is( <<'CODE', <<OUTPUT, "divide by zero" ); 138 .sub _main :main 128 is($P0, 0.002, 'add number to self', PRECISION) 129 .end 130 131 .sub 'sub_number_from_self' 139 132 $P0 = new ['Float'] 140 set $P0, "12.0" 133 $P0 = 1000.2 134 $P0 = $P0  $P0 135 136 is($P0, 0.0, 'sub number from self', PRECISION) 137 .end 138 139 .sub 'multiply_number_by_self' 140 $P0 = new ['Float'] 141 $P0 = 123.4 142 $P0 = $P0 * $P0 143 144 is($P0, 15227.56, 'multiply number by self', PRECISION) 145 .end 146 147 .sub 'divide_number_by_self' 148 $P0 = new ['Float'] 149 $P0 = 1829354.988 150 $P0 = $P0 / $P0 151 152 is($P0, 1.0, 'divide number by self', PRECISION) 153 .end 154 155 .sub 'divide_by_zero' 156 $P0 = new ['Float'] 157 $P0 = 12.0 158 141 159 $P1 = new ['Float'] 160 142 161 $P2 = new ['Float'] 143 set $P2, "0.0" 144 push_eh OK 162 $P2 = 0.0 163 164 push_eh divide_by_zero_handler 145 165 $P1 = $P0 / $P2 146 print "fail\n"147 166 pop_eh 148 OK: 149 get_results '0', $P0 150 $S0 = $P0 151 print "ok\n" 152 print $S0 153 print "\n" 167 nok(1, 'divide by zero') 168 .return () 169 170 divide_by_zero_handler: 171 .get_results ($P1) 172 $S1 = $P1 173 say $S1 174 like($S1, ':s division by zero', 'divide by zero') 154 175 .end 155 CODE156 ok157 float division by zero158 OUTPUT159 176 160 pir_output_is( << 'CODE', << 'OUTPUT', "Truth of a positive float" ); 161 162 .sub _main 177 .sub 'truth_positive_float' 163 178 .local pmc float_1 164 179 float_1 = new ['Float'] 165 180 float_1 = 123.123 166 print float_1 167 if float_1 goto IS_TRUE 168 print " is false\n" 169 end 170 IS_TRUE: 171 print " is true\n" 172 end 181 ok(float_1, 'Truth of a positive float') 173 182 .end 174 CODE175 123.123 is true176 OUTPUT177 183 178 pir_output_is( << 'CODE', << 'OUTPUT', "Truth of a negative float" ); 179 180 .sub _main 184 .sub 'truth_negative_float' 181 185 .local pmc float_1 182 186 float_1 = new ['Float'] 183 187 float_1 = 123.123 184 print float_1 185 if float_1 goto IS_TRUE 186 print " is false\n" 187 end 188 IS_TRUE: 189 print " is true\n" 190 end 188 ok(float_1, 'Truth of a negative float') 191 189 .end 192 CODE193 123.123 is true194 OUTPUT195 190 196 pir_output_is( << 'CODE', << 'OUTPUT', "Truth of a positive integer" ); 197 198 .sub _main 191 .sub 'truth_positive_integer' 199 192 .local pmc float_1 200 193 float_1 = new ['Float'] 201 194 float_1 = 1 202 print float_1 203 if float_1 goto IS_TRUE 204 print " is false\n" 205 end 206 IS_TRUE: 207 print " is true\n" 208 end 195 ok(float_1, 'Truth of a positive integer') 209 196 .end 210 CODE211 1 is true212 OUTPUT213 197 214 pir_output_is( << 'CODE', << 'OUTPUT', "Truth of a negative integer" ); 215 216 .sub _main 198 .sub 'truth_negative_integer' 217 199 .local pmc float_1 218 200 float_1 = new ['Float'] 219 201 float_1 = 1 220 print float_1 221 if float_1 goto IS_TRUE 222 print " is false\n" 223 end 224 IS_TRUE: 225 print " is true\n" 226 end 202 ok(float_1, 'Truth of a negative integer') 227 203 .end 228 CODE229 1 is true230 OUTPUT231 204 232 pir_output_is( << 'CODE', << 'OUTPUT', "Falseness of 0" ); 233 234 .sub _main 205 .sub 'falseness_0' 235 206 .local pmc float_1 236 207 float_1 = new ['Float'] 237 208 float_1 = 0 238 print float_1 239 if float_1 goto IS_TRUE 240 print " is false\n" 241 end 242 IS_TRUE: 243 print " is true\n" 244 end 209 nok(float_1, 'Falseness of 0') 245 210 .end 246 CODE247 0 is false248 OUTPUT249 211 250 pir_output_is( << 'CODE', << 'OUTPUT', "Falseness of 0.000" ); 251 252 .sub _main 212 .sub 'falseness_0.000' 253 213 .local pmc float_1 254 214 float_1 = new ['Float'] 255 215 float_1 = 0.000 256 print float_1 257 if float_1 goto IS_TRUE 258 print " is false\n" 259 end 260 IS_TRUE: 261 print " is true\n" 262 end 216 nok(float_1, 'Falseness of 0.000') 263 217 .end 264 CODE265 0 is false266 OUTPUT267 218 268 pasm_output_is( << "CODE", << 'OUTPUT', "Basic integer arithmetic: addition" ); 269 .include 'fp_equality.pasm' 270 new P0, ['Float'] 271 set P0, 0.001 272 add P0, 1 273 .fp_eq_pasm(P0, 1.001, EQ1) 274 print P0 275 print "not " 276 EQ1: print "ok 1\\n" 219 .sub 'integer_addition' 220 $P0 = new ['Float'] 277 221 278 add P0, 2 279 .fp_eq_pasm(P0, 0.999, EQ2) 280 print P0 281 print "not " 282 EQ2: print "ok 2\\n" 283 end 284 CODE 285 ok 1 286 ok 2 287 OUTPUT 222 $P0 = 0.001 223 $P0 += 1 224 is($P0, 1.001, 'Basic integer arithmetic: addition (1)', PRECISION) 288 225 289 pasm_output_is( << "CODE", << 'OUTPUT', "Basic integer arithmetic: subtraction" ); 290 .include 'fp_equality.pasm' 291 new P0, ['Float'] 292 set P0, 103.45 293 sub P0, 77 294 .fp_eq_pasm(P0, 26.45, EQ1) 295 print P0 296 print "not " 297 EQ1: print "ok 1\\n" 226 $P0 += 2 227 is($P0, 0.999, 'Basic integer arithmetic: addition (2)', PRECISION) 228 .end 298 229 299 sub P0, 24 300 .fp_eq_pasm(P0, 50.45, EQ2) 301 print P0 302 print "not " 303 EQ2: print "ok 2\\n" 304 end 305 CODE 306 ok 1 307 ok 2 308 OUTPUT 230 .sub 'integer_substraction' 231 $P0 = new ['Float'] 309 232 310 pasm_output_is( << "CODE", << 'OUTPUT', "Basic integer arithmetic: multiplication" ); 311 .include 'fp_equality.pasm' 312 new P0, ['Float'] 313 set P0, 0.001 314 mul P0, 10000 315 .fp_eq_pasm(P0, 10.0, EQ1) 316 print P0 317 print "not " 318 EQ1: print "ok 1\\n" 233 $P0 = 103.45 234 $P0 = 77 235 is($P0, 26.45, 'Basic integer arithmetic: subtraction (1)', PRECISION) 319 236 320 mul P0, 1 321 .fp_eq_pasm(P0, 10.0, EQ2) 322 print P0 323 print "not " 324 EQ2: print "ok 2\\n" 237 $P0 = 24 238 is($P0, 50.45, 'Basic integer arithmetic: subtraction (2)', PRECISION) 239 .end 325 240 326 mul P0, 0 327 .fp_eq_pasm(P0, 0.0, EQ3) 328 print P0 329 print "not " 330 EQ3: print "ok 3\\n" 331 end 332 CODE 333 ok 1 334 ok 2 335 ok 3 336 OUTPUT 241 .sub 'integer_multiplication' 242 $P0 = new ['Float'] 337 243 338 pasm_output_is( << "CODE", << 'OUTPUT', "Basic integer arithmetic: division" ); 339 .include 'fp_equality.pasm' 340 new P0, ['Float'] 341 set P0, 1e8 342 div P0, 10000 343 .fp_eq_pasm(P0, 10000.0, EQ1) 344 print P0 345 print "not " 346 EQ1: print "ok 1\\n" 244 $P0 = 0.001 245 $P0 *= 10000 246 is($P0, 10.0, 'Basic integer arithmetic: multiplication (1)', PRECISION) 347 247 348 div P0, 1000000 349 .fp_eq_pasm(P0, 0.01, EQ2) 350 print P0 351 print "not " 352 EQ2: print "ok 2\\n" 353 end 354 CODE 355 ok 1 356 ok 2 357 OUTPUT 248 $P0 *= 1 249 is($P0, 10.0, 'Basic integer arithmetic: multiplication (2)', PRECISION) 358 250 359 pasm_output_is( << "CODE", << 'OUTPUT', "Basic numeric arithmetic: addition" ); 360 .include 'fp_equality.pasm' 361 new P0, ['Float'] 362 set P0, 0.001 363 add P0, 1.2 364 .fp_eq_pasm(P0, 1.201, EQ1) 365 print P0 366 print "not " 367 EQ1: print "ok 1\\n" 251 $P0 *= 0 252 is($P0, 0.0, 'Basic integer arithmetic: multiplication (3)', PRECISION) 253 .end 368 254 369 add P0, 2.4 370 .fp_eq_pasm(P0, 1.199, EQ2) 371 print P0 372 print "not " 373 EQ2: print "ok 2\\n" 374 end 375 CODE 376 ok 1 377 ok 2 378 OUTPUT 255 .sub 'integer_division' 256 $P0 = new ['Float'] 379 257 380 pasm_output_is( << "CODE", << 'OUTPUT', "Basic numeric arithmetic: subtraction" ); 381 .include 'fp_equality.pasm' 382 new P0, ['Float'] 383 set P0, 103.45 384 sub P0, 3.46 385 .fp_eq_pasm(P0, 99.99, EQ1) 386 print P0 387 print "not " 388 EQ1: print "ok 1\\n" 258 $P0 = 1e8 259 $P0 /= 10000 260 is($P0, 10000.0, 'Basic integer arithmetic: division (1)', PRECISION) 389 261 390 sub P0, 0.01 391 .fp_eq_pasm(P0, 100.00, EQ2) 392 print P0 393 print "not " 394 EQ2: print "ok 2\\n" 395 end 396 CODE 397 ok 1 398 ok 2 399 OUTPUT 262 $P0 /= 1000000 263 is($P0, 0.01, 'Basic integer arithmetic: division (2)', PRECISION) 264 .end 400 265 401 pasm_output_is( << "CODE", << 'OUTPUT', "Basic numeric arithmetic: multiplication" ); 402 .include 'fp_equality.pasm' 403 new P0, ['Float'] 404 set P0, 0.001 405 mul P0, 123.5 406 .fp_eq_pasm(P0, 0.1235, EQ1) 407 print P0 408 print "not " 409 EQ1: print "ok 1\\n" 266 .sub 'number_addition' 267 $P0 = new ['Float'] 410 268 411 mul P0, 2.6 412 .fp_eq_pasm(P0, 0.3211, EQ2) 413 print P0 414 print "not " 415 EQ2: print "ok 2\\n" 269 $P0 = 0.001 270 $P0 += 1.2 271 is($P0, 1.201, 'Basic numeric arithmetic: addition (1)', PRECISION) 416 272 417 mul P0, 0 418 .fp_eq_pasm(P0, 0.0, EQ3) 419 print P0 420 print "not " 421 EQ3: print "ok 3\\n" 422 end 423 CODE 424 ok 1 425 ok 2 426 ok 3 427 OUTPUT 273 $P0 += 2.4 274 is($P0, 1.199, 'Basic numeric arithmetic: addition (2)', PRECISION) 275 .end 428 276 429 pasm_output_is( << "CODE", << 'OUTPUT', "Basic numeric arithmetic: division" ); 430 .include 'fp_equality.pasm' 431 new P0, ['Float'] 432 set P0, 1e8 433 div P0, 0.5 434 .fp_eq_pasm(P0, 2e8, EQ1) 435 print P0 436 print "not " 437 EQ1: print "ok 1\\n" 277 .sub 'number_substraction' 278 $P0 = new ['Float'] 438 279 439 div P0, 4000.0 440 .fp_eq_pasm(P0, 50000.0, EQ2) 441 print P0 442 print "not " 443 EQ2: print "ok 2\\n" 444 end 445 CODE 446 ok 1 447 ok 2 448 OUTPUT 280 $P0 = 103.45 281 $P0 = 3.46 282 is($P0, 99.99, 'Basic numeric arithmetic: subtraction (1)', PRECISION) 449 283 450 pasm_output_is( << "CODE", << 'OUTPUT', "Increment & decrement" ); 451 .include 'fp_equality.pasm' 452 new P0, ['Float'] 453 set P0, 0.5 454 inc P0 455 .fp_eq_pasm(P0, 1.5, EQ1) 456 print P0 457 print "not " 458 EQ1: print "ok 1\\n" 284 $P0 = 0.01 285 is($P0, 100.0, 'Basic numeric arithmetic: subtraction (2)', PRECISION) 286 .end 459 287 460 dec P0 461 .fp_eq_pasm(P0, 0.5, EQ2) 462 print P0 463 print "not " 464 EQ2: print "ok 2\\n" 288 .sub 'number_multiplication' 289 $P0 = new ['Float'] 465 290 466 dec P0 467 .fp_eq_pasm(P0, 0.5, EQ3) 468 print P0 469 print "not " 470 EQ3: print "ok 3\\n" 291 $P0 = 0.001 292 $P0 *= 123.5 293 is($P0, 0.1235, 'Basic numeric arithmetic: multiplication (1)', PRECISION) 471 294 472 inc P0 473 .fp_eq_pasm(P0, 0.5, EQ4) 474 print P0 475 print "not " 476 EQ4: print "ok 4\\n" 477 end 478 CODE 479 ok 1 480 ok 2 481 ok 3 482 ok 4 483 OUTPUT 295 $P0 *= 2.6 296 is($P0, 0.3211, 'Basic numeric arithmetic: multiplication (2)', PRECISION) 484 297 485 pasm_output_is( << "CODE", << 'OUTPUT', "Neg" ); 486 .include 'fp_equality.pasm' 487 new P0, ['Float'] 488 set P0, 0.5 489 neg P0 490 .fp_eq_pasm(P0, 0.5, EQ1) 491 print P0 492 print "not " 493 EQ1: print "ok 1\\n" 298 $P0 *= 0.0 299 is($P0, 0.0, 'Basic numeric arithmetic: multiplication (3)', PRECISION) 300 .end 494 301 495 new P1, ['Float'] 496 neg P1, P0 497 .fp_eq_pasm(P1, 0.5, EQ2) 498 print P1 499 print "not " 500 EQ2: print "ok 2\\n" 501 end 502 CODE 503 ok 1 504 ok 2 505 OUTPUT 302 .sub 'number_division' 303 $P0 = new ['Float'] 506 304 507 TODO: { 508 my @todo; 509 @todo = ( todo => '0.0 not implemented, TT #313' ) 510 unless $PConfig{has_negative_zero}; 305 $P0 = 1e8 306 $P0 /= 0.5 307 is($P0, 2e8, 'Basic numeric arithmetic: division (1)', PRECISION) 511 308 512 pasm_output_like( <<'CODE', <<'OUTPUT', 'neg 0', @todo ); 513 new P0, ['Float'] 514 set P0, 0.0 515 neg P0 516 print P0 517 end 518 CODE 519 /^0/ 520 OUTPUT 521 } 309 $P0 /= 4000.0 310 is($P0, 50000.0, 'Basic numeric arithmetic: division (2)', PRECISION) 311 .end 522 312 523 pasm_output_is( << 'CODE', << 'OUTPUT', "Equality" ); 524 new P0, ['Float'] 525 set P0, 1e8 526 new P1, ['Float'] 527 set P1, 1e8 528 new P2, ['Float'] 529 set P2, 2.4 313 .sub 'increment_decrement' 314 $P0 = new ['Float'] 530 315 531 eq P0, P1, OK1 532 print "not " 533 OK1: print "ok 1\n" 316 $P0 = 0.5 317 inc $P0 318 is($P0, 1.5, 'increment (1)', PRECISION) 319 dec $P0 320 is($P0, 0.5, 'decrement (1)', PRECISION) 321 dec $P0 322 is($P0, .5, 'decrement (2)', PRECISION) 323 inc $P0 324 is($P0, 0.5, 'increment (2)', PRECISION) 325 .end 534 326 535 eq P0, P2, BAD2 536 branch OK2 537 BAD2: print "not " 538 OK2: print "ok 2\n" 327 .sub 'neg' 328 $P0 = new ['Float'] 329 $P0 = 0.5 330 neg $P0 331 is($P0, 0.5, 'Neg', PRECISION) 539 332 540 ne P0, P2, OK3 541 print "not " 542 OK3: print "ok 3\n" 333 $P1 = new ['Float'] 334 $P1 =  $P0 335 is($P1, 0.5, 'Neg is involutive', PRECISION) 336 .end 543 337 544 ne P0, P1, BAD4 545 branch OK4 546 BAD4: print "not " 547 OK4: print "ok 4\n" 338 .sub 'negative_zero' 339 load_bytecode 'config.pbc' 340 $P1 = _config() 341 $P2 = $P1['has_negative_zero'] 342 unless $P2 goto negative_zero_todoed 548 343 549 eq_num P0, P1, OK5550 print "not "551 OK5: print "ok 5\n" 344 $P0 = new ['Float'] 345 $P0 = 0.0 346 neg $P0 552 347 553 eq_num P0, P2, BAD6 554 branch OK6 555 BAD6: print "not " 556 OK6: print "ok 6\n" 348 $S0 = $P0 349 like($S0, '^\0', 'negative zero') 350 .return () 557 351 558 ne_num P0, P2, OK7559 print "not "560 OK7: print "ok 7\n" 352 negative_zero_todoed: 353 todo(1, '0.0 not implemented, TT#313') 354 .end 561 355 562 ne_num P0, P1, BAD8 563 branch OK8 564 BAD8: print "not " 565 OK8: print "ok 8\n" 566 end 567 CODE 568 ok 1 569 ok 2 570 ok 3 571 ok 4 572 ok 5 573 ok 6 574 ok 7 575 ok 8 576 OUTPUT 356 .sub 'equality' 357 $P0 = new ['Float'] 358 $P0 = 1e8 577 359 578 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" ); 360 $P1 = new ['Float'] 361 $P1 = 1e8 579 362 580 .sub _main 363 $P2 = new ['Float'] 364 $P2 = 2.4 365 366 $I0 = 1 367 if $P0 == $P1 goto equality_1 368 $I0 = 0 369 equality_1: 370 ok($I0, 'equal floats') 371 372 $I0 = 0 373 if $P0 == $P2 goto equality_2 374 $I0 = 1 375 equality_2: 376 ok($I0, 'different floats are not equal') 377 378 $I0 = 1 379 if $P0 != $P2 goto equality_3 380 $I0 = 0 381 equality_3: 382 ok($I0, "different floats are different") 383 384 $I0 = 0 385 if $P0 != $P1 goto equality_4 386 $I0 = 1 387 equality_4: 388 ok($I0, "equal floats aren't different") 389 390 $I0 = 1 391 eq_num $P0, $P1, equality_5 392 $I0 = 0 393 equality_5: 394 ok($I0, "equal floats are eq_num") 395 396 $I0 = 0 397 eq_num $P0, $P2, equality_6 398 $I0 = 1 399 equality_6: 400 ok($I0, "different floats aren't eq_num") 401 402 $I0 = 1 403 ne_num $P0, $P2, equality_7 404 $I0 = 0 405 equality_7: 406 ok($I0, "different floats are ne_num") 407 408 $I0 = 0 409 ne_num $P0, $P1, equality_8 410 $I0 = 1 411 equality_8: 412 ok($I0, "equal floats aren't ne_num") 413 .end 414 415 .sub 'is_interface_done' 581 416 .local pmc pmc1 582 pmc1 = new ['Float']583 417 .local int bool1 584 does bool1, pmc1, "scalar"585 print bool1 586 print "\n"587 does bool1, pmc1, "float"588 print bool1 589 print "\n"590 does bool1, pmc1, "no_interface"591 print bool1 592 print "\n"593 end418 pmc1 = new ['Float'] 419 420 bool1 = does pmc1, "scalar" 421 ok(bool1, 'Float does "scalar"') 422 423 bool1 = does pmc1, "float" 424 ok(bool1, 'Float does "float"') 425 426 bool1 = does pmc1, "no_interface" 427 nok(bool1, 'Float does not "no_interface"') 594 428 .end 595 CODE596 1597 1598 0599 OUTPUT600 429 601 pasm_output_is( << "CODE", << 'OUTPUT', "Abs" ); 602 .include 'fp_equality.pasm' 603 new P0, ['Float'] 604 set P0, 1.0 605 abs P0 606 eq P0, P0, OK1 607 print P0 608 print "not " 609 OK1: print "ok 1\\n" 430 .sub 'abs' 431 $P0 = new ['Float'] 432 $P0 = 1.0 433 abs $P0 434 is($P0, $P0, 'abs does not change positive floats') 610 435 611 set P0, 1.0 612 abs P0 613 .fp_eq_pasm(P0, 1.0, OK2) 614 print P0 615 print "not " 616 OK2: print "ok 2\\n" 436 $P0 = 1.0 437 abs $P0 438 is($P0, 1.0, 'abs of 1.0', PRECISION) 617 439 618 new P1, ['Float'] 619 set P0, 5.0 620 abs P1, P0 621 .fp_eq_pasm(P1, 5.0, OK3) 622 print P1 623 print "not " 624 OK3: print "ok 3\\n" 625 end 626 CODE 627 ok 1 628 ok 2 629 ok 3 630 OUTPUT 440 $P0 = 5.0 441 abs $P0 442 is($P0, 5.0, 'abs of 5.0', PRECISION) 443 .end 631 444 632 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: lt" ); 633 new P1,['Float']634 set P1, 111.1635 set N1,P1445 .sub 'lt' 446 $P1 = new ['Float'] 447 $P1 = 111.11 448 $N1 = $P1 636 449 637 lt P1, 111.2, OK1 638 print "not " 639 OK1: print "ok 1\n" 450 $I0 = 1 451 lt $P1, 111.12, lt_1 452 $I0 = 0 453 lt_1: 454 ok($I0, 'lt ok') 640 455 641 lt P1, N1, BAD2 642 branch OK2 643 BAD2: print "not " 644 OK2: print "ok 2\n" 456 $I0 = 0 457 lt $P1, $N1, lt_2 458 $I0 = 1 459 lt_2: 460 ok($I0, 'lt irreflexive') 645 461 646 lt P1, 111.0, BAD3 647 branch OK3 648 BAD3: print "not " 649 OK3: print "ok 3\n" 650 end 651 CODE 652 ok 1 653 ok 2 654 ok 3 655 OUTPUT 462 $I0 = 0 463 lt $P1, 111.0, lt_3 464 $I0 = 1 465 lt_3: 466 ok($I0, 'not lt') 467 .end 656 468 657 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: lt_num" ); 658 new P1, ['Float'] 659 set P1, 1.1 660 new P2, ['Float'] 661 set P2, 1.2 662 new P3, ['Float'] 663 set P3, 1.0 664 new P4, ['Float'] 665 set P4, P1 469 .sub 'lt_num' 470 $P1 = new ['Float'] 471 $P1 = 1.1 666 472 667 lt_num P1, P2, OK1 668 print "not " 669 OK1: print "ok 1\n" 473 $P2 = new ['Float'] 474 $P2 = 1.2 670 475 671 lt_num P1, P4, BAD2 672 branch OK2 673 BAD2: print "not " 674 OK2: print "ok 2\n" 476 $P3 = new ['Float'] 477 $P3 = 1.0 675 478 676 lt_num P1, P3, BAD3 677 branch OK3 678 BAD3: print "not " 679 OK3: print "ok 3\n" 680 end 681 CODE 682 ok 1 683 ok 2 684 ok 3 685 OUTPUT 479 $P4 = new ['Float'] 480 $P4 = $P1 686 481 687 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: le" ); 688 new P1, ['Float'] 689 set P1, 111.1 690 set N1, P1 482 $I0 = 1 483 lt_num $P1, $P2, lt_num_1 484 $I0 = 0 485 lt_num_1: 486 ok($I0, 'lt_num true') 691 487 692 le P1, 111.2, OK1 693 print "not " 694 OK1: print "ok 1\n" 488 $I0 = 0 489 lt_num $P1, $P4, lt_num_2 490 $I0 = 1 491 lt_num_2: 492 ok($I0, 'lt_num irreflexive') 695 493 696 le P1, N1, OK2 697 print "not " 698 OK2: print "ok 2\n" 494 $I0 = 0 495 lt_num $P1, $P3, lt_num_3 496 $I0 = 1 497 lt_num_3: 498 ok($I0, 'lt_num false') 499 .end 699 500 700 le P1, 111.0, BAD3 701 branch OK3 702 BAD3: print "not " 703 OK3: print "ok 3\n" 704 end 705 CODE 706 ok 1 707 ok 2 708 ok 3 709 OUTPUT 501 .sub 'le' 502 $P1 = new ['Float'] 503 $P1 = 111.1 504 $N1 = $P1 710 505 711 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: le_num" ); 712 new P1, ['Float'] 713 set P1, 1.1 714 new P2, ['Float'] 715 set P2, 1.2 716 new P3, ['Float'] 717 set P3, 1.0 718 new P4, ['Float'] 719 set P4, P1 506 $I0 = 1 507 le $P1, 111.2, le_1 508 $I0 = 0 509 le_1: 510 ok($I0, 'le_p_nc') 720 511 721 le_num P1, P2, OK1 722 print "not " 723 OK1: print "ok 1\n" 512 $I0 = 1 513 le $P1, $N1, le_2 514 $I0 = 0 515 le_2: 516 ok($I0, 'le_p_n') 724 517 725 le_num P1, P4, OK2 726 print "not " 727 OK2: print "ok 2\n" 518 $I0 = 0 519 le $P1, 111.0, le_3 520 $I0 = 1 521 le_3: 522 ok($I0, 'le_p_nc false') 728 523 729 le_num P1, P3, BAD3 730 branch OK3 731 BAD3: print "not " 732 OK3: print "ok 3\n" 733 end 734 CODE 735 ok 1 736 ok 2 737 ok 3 738 OUTPUT 524 $I0 = 1 525 le $P1, $P1, le_4 526 $I0 = 0 527 le_4: 528 ok($I0, 'le reflexive') 529 .end 739 530 740 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: gt" ); 741 new P1, ['Float'] 742 set P1, 111.1 743 set N1, P1 531 .sub 'le_num' 532 $P1 = new ['Float'] 533 $P1 = 1.1 744 534 745 gt P1, 111.2, BAD1 746 branch OK1 747 BAD1: print "not " 748 OK1: print "ok 1\n" 535 $P2 = new ['Float'] 536 $P2 = 1.2 749 537 750 gt P1, N1, OK2 751 branch OK2 752 BAD2: print "not " 753 OK2: print "ok 2\n" 538 $P3 = new ['Float'] 539 $P3 = 1.0 754 540 755 gt P1, 111.0, OK3 756 print "not " 757 OK3: print "ok 3\n" 758 end 759 CODE 760 ok 1 761 ok 2 762 ok 3 763 OUTPUT 541 $P4 = new ['Float'] 542 $P4 = $P1 764 543 765 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: gt_num" ); 766 new P1, ['Float'] 767 set P1, 1.1 768 new P2, ['Float'] 769 set P2, 1.2 770 new P3, ['Float'] 771 set P3, 1.0 772 new P4, ['Float'] 773 set P4, P1 544 $I0 = 1 545 le_num $P1, $P2, le_num_1 546 $I0 = 0 547 le_num_1: 548 ok($I0, 'le_num true') 774 549 775 gt_num P1, P2, BAD1 776 branch OK1 777 BAD1: print "not " 778 OK1: print "ok 1\n" 550 $I0 = 1 551 le_num $P1, $P4, le_num_2 552 $I0 = 0 553 le_num_2: 554 ok($I0, 'le_num reflexive') 779 555 780 gt_num P1, P4, OK2 781 branch OK2 782 BAD2: print "not " 783 OK2: print "ok 2\n" 556 $I0 = 0 557 le_num $P1, $P3, le_num_3 558 $I0 = 1 559 le_num_3: 560 ok($I0, 'le_num false') 561 .end 784 562 785 gt_num P1, P3, OK3 786 print "not " 787 OK3: print "ok 3\n" 788 end 789 CODE 790 ok 1 791 ok 2 792 ok 3 793 OUTPUT 563 .sub 'gt' 564 $P1 = new ['Float'] 565 $P1 = 111.1 566 $N1 = $P1 794 567 795 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: ge" ); 796 new P1, ['Float'] 797 set P1, 111.1 798 set N1, P1 568 $I0 = 0 569 gt $P1, 111.2, gt_1 570 $I0 = 1 571 gt_1: 572 ok($I0, 'comparison ops: gt nok') 799 573 800 ge P1, 111.2, BAD1 801 branch OK1 802 BAD1: print "not " 803 OK1: print "ok 1\n" 574 $I0 = 1 575 gt $P1, $N1, gt_2 576 $I0 = 0 577 gt_2: 578 nok($I0, 'comparison ops: gt irreflexive') 804 579 805 ge P1, N1, OK2 806 print "not " 807 OK2: print "ok 2\n" 580 $I0 = 1 581 gt $P1, 111.0, gt_3 582 $I0 = 0 583 gt_3: 584 ok($I0, 'comparison ops: gt ok') 585 .end 808 586 809 ge P1, 111.0, OK3 810 print "not " 811 OK3: print "ok 3\n" 812 end 813 CODE 814 ok 1 815 ok 2 816 ok 3 817 OUTPUT 587 .sub 'gt_num' 588 $P1 = new ['Float'] 589 $P2 = new ['Float'] 590 $P3 = new ['Float'] 591 $P4 = new ['Float'] 818 592 819 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: ge_num" ); 820 new P1, ['Float'] 821 set P1, 1.1 822 new P2, ['Float'] 823 set P2, 1.2 824 new P3, ['Float'] 825 set P3, 1.0 826 new P4, ['Float'] 827 set P4, P1 593 $P1 = 1.1 594 $P2 = 1.2 595 $P3 = 1.0 596 $P4 = $P1 828 597 829 ge_num P1, P2, BAD1 830 branch OK1 831 BAD1: print "not " 832 OK1: print "ok 1\n" 598 $I0 = 0 599 gt_num $P1, $P2, gt_num_1 600 $I0 = 1 601 gt_num_1: 602 ok($I0, 'comparison ops: gt_num nok') 833 603 834 ge_num P1, P4, OK2 835 print "not " 836 OK2: print "ok 2\n" 604 $I0 = 0 605 gt_num $P1, $P4, gt_num_2 606 $I0 = 1 607 gt_num_2: 608 ok($I0, 'comparison ops: gt_num irreflexive') 837 609 838 ge_num P1, P3, OK3 839 print "not " 840 OK3: print "ok 3\n" 841 end 842 CODE 843 ok 1 844 ok 2 845 ok 3 846 OUTPUT 610 $I0 = 1 611 gt_num $P1, $P3, gt_num_3 612 $I0 = 0 613 gt_num_3: 614 ok($I0, 'comparison ops: gt_num ok') 615 .end 847 616 848 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: cmp_p_n" ); 849 new P1, ['Float'] 850 set P1, 123.45 851 set N1, 123.45 852 set N2, 1.0 853 set N3, 123.54 617 .sub 'ge' 618 $P1 = new ['Float'] 619 $P1 = 111.1 620 $N1 = $P1 854 621 855 cmp I0, P1, N1 856 print I0 857 print "\n" 858 cmp I0, P1, N2 859 print I0 860 print "\n" 861 cmp I0, P1, N3 862 print I0 863 print "\n" 864 end 865 CODE 866 0 867 1 868 1 869 OUTPUT 622 $I0 = 0 623 ge $P1, 111.2, ge_1 624 $I0 = 1 625 ge_1: 626 ok($I0, 'comparison ops: ge nok') 870 627 871 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isgt" ); 872 new P1, ['Float'] 873 new P2, ['Float'] 874 new P3, ['Float'] 875 new P4, ['Integer'] 876 new P5, ['Integer'] 877 new P6, ['Float'] 628 $I0 = 1 629 ge $P1, $N1, ge_2 630 $I0 = 0 631 ge_2: 632 ok($I0, 'comparison ops: ge reflexive') 878 633 879 set P1, 10.0880 set P2, 20.0881 set P3, 5.0882 set P4, 3883 set P5, 12884 set P6, 10.0 634 $I0 = 1 635 ge $P1, 111.0, ge_3 636 $I0 = 0 637 ge_3: 638 ok($I0, 'comparison ops: ge ok') 639 .end 885 640 886 isgt I0, P1, P2 887 print I0 888 print "\n" 889 isgt I0, P1, P1 890 print I0 891 print "\n" 892 isgt I0, P1, P3 893 print I0 894 print "\n" 895 isgt I0, P1, P4 896 print I0 897 print "\n" 898 isgt I0, P1, P5 899 print I0 900 print "\n" 901 isgt I0, P1, P6 902 print I0 903 print "\n" 904 end 905 CODE 906 0 907 0 908 1 909 1 910 0 911 0 912 OUTPUT 641 .sub 'ge_num' 642 $P1 = new ['Float'] 643 $P2 = new ['Float'] 644 $P3 = new ['Float'] 645 $P4 = new ['Float'] 913 646 914 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isge" ); 915 new P1, ['Float'] 916 new P2, ['Float'] 917 new P3, ['Float'] 918 new P4, ['Integer'] 919 new P5, ['Integer'] 920 new P6, ['Float'] 647 $P1 = 1.1 648 $P2 = 1.2 649 $P3 = 1.0 650 $P4 = $P1 921 651 922 set P1, 10.0 923 set P2, 20.0 924 set P3, 5.0 925 set P4, 3 926 set P5, 12 927 set P6, 10.0 652 $I0 = 0 653 ge_num $P1, $P2, ge_num_1 654 $I0 = 1 655 ge_num_1: 656 ok($I0, 'comparison ops: ge_num nok') 928 657 929 isge I0, P1, P2 930 print I0 931 print "\n" 932 isge I0, P1, P1 933 print I0 934 print "\n" 935 isge I0, P1, P3 936 print I0 937 print "\n" 938 isge I0, P1, P4 939 print I0 940 print "\n" 941 isge I0, P1, P5 942 print I0 943 print "\n" 944 isge I0, P1, P6 945 print I0 946 print "\n" 947 end 948 CODE 949 0 950 1 951 1 952 1 953 0 954 1 955 OUTPUT 658 $I0 = 1 659 ge_num $P1, $P4, ge_num_2 660 $I0 = 0 661 ge_num_2: 662 ok($I0, 'comparison ops: ge_num reflexive') 956 663 957 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: islt" ); 958 new P1, ['Float'] 959 new P2, ['Float'] 960 new P3, ['Float'] 961 new P4, ['Integer'] 962 new P5, ['Integer'] 963 new P6, ['Float'] 664 $I0 = 1 665 ge_num $P1, $P3, ge_num_3 666 $I0 = 0 667 ge_num_3: 668 ok($I0, 'comparison ops: ge_num ok') 669 .end 964 670 965 set P1, 10.0 966 set P2, 20.0967 set P3, 5.0968 set P4, 3969 set P5, 12970 set P6, 10.0671 .sub 'cmp_p_n' 672 $P1 = new ['Float'] 673 $P1 = 123.45 674 $N1 = 123.45 675 $N2 = 1.0 676 $N3 = 123.54 971 677 972 islt I0, P1, P2 973 print I0 974 print "\n" 975 islt I0, P1, P1 976 print I0 977 print "\n" 978 islt I0, P1, P3 979 print I0 980 print "\n" 981 islt I0, P1, P4 982 print I0 983 print "\n" 984 islt I0, P1, P5 985 print I0 986 print "\n" 987 islt I0, P1, P6 988 print I0 989 print "\n" 990 end 991 CODE 992 1 993 0 994 0 995 0 996 1 997 0 998 OUTPUT 678 $I0 = cmp $P1, $N1 679 is($I0, 0, 'comparison ops: cmp_p_n: equality') 999 680 1000 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isle" ); 1001 new P1, ['Float'] 1002 new P2, ['Float'] 1003 new P3, ['Float'] 1004 new P4, ['Integer'] 1005 new P5, ['Integer'] 1006 new P6, ['Float'] 681 $I0 = cmp $P1, $N2 682 is($I0, 1, 'comparison ops: cmp_p_n: gt') 1007 683 1008 set P1, 10.0 1009 set P2, 20.0 1010 set P3, 5.0 1011 set P4, 3 1012 set P5, 12 1013 set P6, 10.0 684 $I0 = cmp $P1, $N3 685 is($I0, 1, 'comparison ops: cmp_p_n: lt') 686 .end 1014 687 1015 isle I0, P1, P2 1016 print I0 1017 print "\n" 1018 isle I0, P1, P1 1019 print I0 1020 print "\n" 1021 isle I0, P1, P3 1022 print I0 1023 print "\n" 1024 isle I0, P1, P4 1025 print I0 1026 print "\n" 1027 isle I0, P1, P5 1028 print I0 1029 print "\n" 1030 isle I0, P1, P6 1031 print I0 1032 print "\n" 1033 end 1034 CODE 1035 1 1036 1 1037 0 1038 0 1039 1 1040 1 1041 OUTPUT 688 .sub 'isgt' 689 $P1 = new ['Float'] 690 $P2 = new ['Float'] 691 $P3 = new ['Float'] 692 $P4 = new ['Integer'] 693 $P5 = new ['Integer'] 694 $P6 = new ['Float'] 1042 695 1043 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: iseq" ); 1044 new P1, ['Float'] 1045 new P2, ['Float'] 1046 new P3, ['Float'] 1047 new P4, ['Integer'] 696 $P1 = 10.0 697 $P2 = 20.0 698 $P3 = 5.0 699 $P4 = 3 700 $P5 = 12 701 $P6 = 10.0 1048 702 1049 set P1, 2.5 1050 set P2, 2.6 1051 set P3, 2.5 1052 set P4, 2 703 $I0 = isgt $P1, $P2 704 nok($I0, 'comparison ops: isgt nok') 1053 705 1054 iseq I0, P1, P1 1055 print I0 1056 print "\n" 1057 iseq I0, P1, P2 1058 print I0 1059 print "\n" 1060 iseq I0, P1, P3 1061 print I0 1062 print "\n" 1063 iseq I0, P1, P4 1064 print I0 1065 print "\n" 1066 end 1067 CODE 1068 1 1069 0 1070 1 1071 0 1072 OUTPUT 706 $I0 = isgt $P1, $P1 707 nok($I0, 'comparison ops: isgt irreflexive') 1073 708 1074 pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isne" ); 1075 new P1, ['Float'] 1076 new P2, ['Float'] 1077 new P3, ['Float'] 1078 new P4, ['Integer'] 709 $I0 = isgt $P1, $P3 710 ok($I0, 'comparison ops: isgt ok') 1079 711 1080 set P1, 2.5 1081 set P2, 2.6 1082 set P3, 2.5 1083 set P4, 2 712 $I0 = isgt $P1, $P4 713 ok($I0, 'comparison ops: isgt ok with Float and Integer') 1084 714 1085 isne I0, P1, P1 1086 print I0 1087 print "\n" 1088 isne I0, P1, P2 1089 print I0 1090 print "\n" 1091 isne I0, P1, P3 1092 print I0 1093 print "\n" 1094 isne I0, P1, P4 1095 print I0 1096 print "\n" 1097 end 1098 CODE 1099 0 1100 1 1101 0 1102 1 1103 OUTPUT 715 $I0 = isgt $P1, $P5 716 nok($I0, 'comparison ops: isgt nok with Float and Integer') 1104 717 1105 pir_output_is( <<'CODE', <<OUTPUT, "instantiate_str" ); 1106 .sub main :main 1107 .const 'Float' pi = "3.1" 1108 print pi 1109 print "\n" 718 $I0 = isgt $P1, $P6 719 nok($I0, 'comparison ops: isgt irreflexive (different PMCs)') 1110 720 .end 1111 CODE1112 3.11113 OUTPUT1114 721 1115 pir_output_is( <<'CODE', <<'OUTPUT', 'cmp functions for subclasses' ); 1116 .sub main :main 1117 $P0 = subclass 'Float', 'Flt' 722 .sub 'isge' 723 $P1 = new ['Float'] 724 $P2 = new ['Float'] 725 $P3 = new ['Float'] 726 $P4 = new ['Integer'] 727 $P5 = new ['Integer'] 728 $P6 = new ['Float'] 1118 729 1119 $P1 = new ['Flt'] 1120 $P1 = 1.5 1121 $P2 = new ['Flt'] 1122 $P2 = 2.73 730 $P1 = 10.0 731 $P2 = 20.0 732 $P3 = 5.0 733 $P4 = 3 734 $P5 = 12 735 $P6 = 10.0 1123 736 1124 $I0 = cmp $P1, $P2 1125 say $I0 1126 $I0 = cmp $P1, $P1 1127 say $I0 1128 $I0 = cmp $P2, $P1 1129 say $I0 1130 .end 1131 CODE 1132 1 1133 0 1134 1 1135 OUTPUT 737 $I0 = isge $P1, $P2 738 nok($I0, 'comparison ops: isge nok') 1136 739 1137 pir_output_is( <<'CODE', <<'OUTPUT', 'acos as a method' ); 1138 .include 'fp_equality.pasm' 1139 .sub main :main 1140 .local pmc array 1141 array = new 'FixedFloatArray' 1142 array = 2 1143 $P0 = new ['Float'] 1144 $P0 = 0.0 1145 $P1 = $P0.'acos'() 1146 array[0] = $P0 1147 array[1] = $P1 1148 $S0 = sprintf "acos(%.1f) is %.9f", array 1149 say $S0 740 $I0 = isge $P1, $P1 741 ok($I0, 'comparison ops: isge reflexive') 1150 742 1151 $P2 = new ['Float'] 1152 $P2 = 0.5 1153 $P3 = $P2.'acos'() 1154 array[0] = $P2 1155 array[1] = $P3 1156 $S0 = sprintf "acos(%.1f) is %.9f", array 1157 say $S0 1158 .end 1159 CODE 1160 acos(0.0) is 1.570796327 1161 acos(0.5) is 1.047197551 1162 OUTPUT 743 $I0 = isge $P1, $P3 744 ok($I0, 'comparison ops: isge ok') 1163 745 1164 pir_output_is( <<'CODE', <<'OUTPUT', 'cos as a method' ); 1165 .include 'fp_equality.pasm' 1166 .sub main :main 1167 .local pmc array 1168 array = new 'FixedFloatArray' 1169 array = 2 1170 $P0 = new ['Float'] 1171 $P0 = 0.0 1172 $P1 = $P0.'cos'() 1173 array[0] = $P0 1174 array[1] = $P1 1175 $S0 = sprintf "cos(%.1f) is %.9f", array 1176 say $S0 746 $I0 = isge $P1, $P4 747 ok($I0, 'comparison ops: isge ok with Float and Integer') 1177 748 1178 $P2 = new ['Float'] 1179 $P2 = 0.5 1180 $P3 = $P2.'cos'() 1181 array[0] = $P2 1182 array[1] = $P3 1183 $S0 = sprintf "cos(%.1f) is %.9f", array 1184 say $S0 749 $I0 = isge $P1, $P5 750 nok($I0, 'comparison ops: isge nok with Float and Integer') 751 752 $I0 = isge $P1, $P6 753 ok($I0, 'comparison ops: isge reflexive (different PMCs)') 1185 754 .end 1186 CODE1187 cos(0.0) is 1.0000000001188 cos(0.5) is 0.8775825621189 OUTPUT1190 755 1191 pir_output_is( <<'CODE', <<'OUTPUT', 'asec as a method' ); 1192 .include 'fp_equality.pasm' 1193 .sub main :main 1194 .local pmc array 1195 array = new 'FixedFloatArray' 1196 array = 2 1197 $P0 = new ['Float'] 1198 $P0 = 1.0 1199 $P1 = $P0.'asec'() 1200 array[0] = $P0 1201 array[1] = $P1 1202 $S0 = sprintf "asec(%.1f) is %.9f", array 1203 say $S0 1204 756 .sub 'islt' 757 $P1 = new ['Float'] 1205 758 $P2 = new ['Float'] 1206 $P2 = 3.0 1207 $P3 = $P2.'asec'() 1208 array[0] = $P2 1209 array[1] = $P3 1210 $S0 = sprintf "asec(%.1f) is %.9f", array 1211 say $S0 1212 .end 1213 CODE 1214 asec(1.0) is 0.000000000 1215 asec(3.0) is 1.230959417 1216 OUTPUT 759 $P3 = new ['Float'] 760 $P4 = new ['Integer'] 761 $P5 = new ['Integer'] 762 $P6 = new ['Float'] 1217 763 1218 pir_output_is( <<'CODE', <<'OUTPUT', 'asin as a method' ); 1219 .include 'fp_equality.pasm' 1220 .sub main :main 1221 .local pmc array 1222 array = new 'FixedFloatArray' 1223 array = 2 1224 $P0 = new ['Float'] 1225 $P0 = 0.0 1226 $P1 = $P0.'asin'() 1227 array[0] = $P0 1228 array[1] = $P1 1229 $S0 = sprintf "asin(%.1f) is %.9f", array 1230 say $S0 764 $P1 = 10.0 765 $P2 = 20.0 766 $P3 = 5.0 767 $P4 = 3 768 $P5 = 12 769 $P6 = 10.0 1231 770 1232 $P2 = new ['Float'] 1233 $P2 = 0.5 1234 $P3 = $P2.'asin'() 1235 array[0] = $P2 1236 array[1] = $P3 1237 $S0 = sprintf "asin(%.1f) is %.9f", array 1238 say $S0 1239 .end 1240 CODE 1241 asin(0.0) is 0.000000000 1242 asin(0.5) is 0.523598776 1243 OUTPUT 771 $I0 = islt $P1, $P2 772 ok($I0, 'comparison ops: islt ok') 1244 773 1245 pir_output_is( <<'CODE', <<'OUTPUT', 'atan as a method' ); 1246 .include 'fp_equality.pasm' 1247 .sub main :main 1248 .local pmc array 1249 array = new 'FixedFloatArray' 1250 array = 2 1251 $P0 = new ['Float'] 1252 $P0 = 0.0 1253 $P1 = $P0.'atan'() 1254 array[0] = $P0 1255 array[1] = $P1 1256 $S0 = sprintf "atan(%.1f) is %.9f", array 1257 say $S0 774 $I0 = islt $P1, $P1 775 nok($I0, 'comparison ops: islt irreflexive') 1258 776 1259 $P2 = new ['Float'] 1260 $P2 = 0.5 1261 $P3 = $P2.'atan'() 1262 array[0] = $P2 1263 array[1] = $P3 1264 $S0 = sprintf "atan(%.1f) is %.9f", array 1265 say $S0 777 $I0 = islt $P1, $P3 778 nok($I0, 'comparison ops: islt nok') 779 780 $I0 = islt $P1, $P4 781 nok($I0, 'comparison ops: islt nok with Float and Integer') 782 783 $I0 = islt $P1, $P5 784 ok($I0, 'comparison ops: islt ok with Float and Integer') 785 786 $I0 = islt $P1, $P6 787 nok($I0, 'comparison ops: islt irreflexive (different PMCs)') 1266 788 .end 1267 CODE1268 atan(0.0) is 0.0000000001269 atan(0.5) is 0.4636476091270 OUTPUT1271 789 1272 pir_output_is( <<'CODE', <<'OUTPUT', 'atan2 as a method' ); 1273 .include 'fp_equality.pasm' 1274 .sub main :main 1275 .local pmc array 1276 array = new 'FixedFloatArray' 1277 array = 3 1278 $P0 = new ['Float'] 790 .sub 'isle' 1279 791 $P1 = new ['Float'] 1280 $P0 = 0.7 1281 $P1 = 0.5 1282 $P2 = $P0.'atan2'($P1) 1283 array[0] = $P0 1284 array[1] = $P1 1285 array[2] = $P2 1286 $S0 = sprintf "atan2(%.1f, %.1f) is %.9f", array 1287 say $S0 1288 .end 1289 CODE 1290 atan2(0.7, 0.5) is 0.950546841 1291 OUTPUT 792 $P2 = new ['Float'] 793 $P3 = new ['Float'] 794 $P4 = new ['Integer'] 795 $P5 = new ['Integer'] 796 $P6 = new ['Float'] 1292 797 1293 pir_output_is( <<'CODE', <<'OUTPUT', 'cosh as a method' ); 1294 .include 'fp_equality.pasm' 1295 .sub main :main 1296 .local pmc array 1297 array = new 'FixedFloatArray' 1298 array = 2 1299 $P0 = new ['Float'] 1300 $P0 = 0.0 1301 $P1 = $P0.'cosh'() 1302 array[0] = $P0 1303 array[1] = $P1 1304 $S0 = sprintf "cosh(%.1f) is %.9f", array 1305 say $S0 798 $P1 = 10.0 799 $P2 = 20.0 800 $P3 = 5.0 801 $P4 = 3 802 $P5 = 12 803 $P6 = 10.0 1306 804 1307 $P2 = new ['Float'] 1308 $P2 = 0.5 1309 $P3 = $P2.'cosh'() 1310 array[0] = $P2 1311 array[1] = $P3 1312 $S0 = sprintf "cosh(%.1f) is %.9f", array 1313 say $S0 805 $I0 = isle $P1, $P2 806 ok($I0, 'comparison ops: isle ok') 807 808 $I0 = isle $P1, $P1 809 ok($I0, 'comparison ops: isle reflexive') 810 811 $I0 = isle $P1, $P3 812 nok($I0, 'comparison ops: isle nok') 813 814 $I0 = isle $P1, $P4 815 nok($I0, 'comparison ops: isle nok with Float and Integer') 816 817 $I0 = isle $P1, $P5 818 ok($I0, 'comparison ops: isle ok with Float and Integer') 819 820 $I0 = isle $P1, $P6 821 ok($I0, 'comparison ops: isle reflexive (different PMCs)') 1314 822 .end 1315 CODE1316 cosh(0.0) is 1.0000000001317 cosh(0.5) is 1.1276259651318 OUTPUT1319 823 1320 pir_output_is( <<'CODE', <<'OUTPUT', 'exp as a method' ); 1321 .include 'fp_equality.pasm' 1322 .sub main :main 1323 .local pmc array 1324 array = new 'FixedFloatArray' 1325 array = 2 1326 $P0 = new ['Float'] 1327 $P0 = 0.0 1328 $P1 = $P0.'exp'() 1329 array[0] = $P0 1330 array[1] = $P1 1331 $S0 = sprintf "exp(%.1f) is %.9f", array 1332 say $S0 824 .sub 'iseq' 825 $P1 = new ['Float'] 826 $P2 = new ['Float'] 827 $P3 = new ['Float'] 828 $P4 = new ['Integer'] 1333 829 830 $P1 = 2.5 831 $P2 = 2.6 832 $P3 = 2.5 833 $P4 = 2 834 835 $I0 = iseq $P1, $P1 836 ok($I0, 'iseq reflexive, same PMC') 837 838 $I0 = iseq $P1, $P3 839 ok($I0, 'iseq reflexive, different PMCs') 840 841 $I0 = iseq $P1, $P2 842 nok($I0, 'iseq nok with two Floats') 843 844 $I0 = iseq $P1, $P4 845 nok($I0, 'iseq nok between an Integer and a Float') 846 .end 847 848 .sub 'isne' 849 $P1 = new ['Float'] 1334 850 $P2 = new ['Float'] 1335 $P2 = 0.5 1336 $P3 = $P2.'exp'() 1337 array[0] = $P2 1338 array[1] = $P3 1339 $S0 = sprintf "exp(%.1f) is %.9f", array 1340 say $S0 851 $P3 = new ['Float'] 852 $P4 = new ['Integer'] 853 854 $P1 = 2.5 855 $P2 = 2.6 856 $P3 = 2.5 857 $P4 = 2 858 859 $I0 = isne $P1, $P1 860 nok($I0, 'isne irreflexive, same PMC') 861 862 $I0 = isne $P1, $P3 863 nok($I0, 'isne irreflexive, different PMCs') 864 865 $I0 = isne $P1, $P2 866 ok($I0, 'isne ok with two Floats') 867 868 $I0 = isne $P1, $P4 869 ok($I0, 'isne ok between an Integer and a Float') 1341 870 .end 1342 CODE1343 exp(0.0) is 1.0000000001344 exp(0.5) is 1.6487212711345 OUTPUT1346 871 1347 pir_output_is( <<'CODE', <<'OUTPUT', 'ln as a method' ); 1348 .include 'fp_equality.pasm' 1349 .sub main :main 1350 .local pmc array 1351 array = new 'FixedFloatArray' 1352 array = 2 1353 $P0 = new ['Float'] 1354 $P0 = 45.0 1355 $P1 = $P0.'ln'() 1356 array[0] = $P0 1357 array[1] = $P1 1358 $S0 = sprintf "ln(%.1f) is %.9f", array 1359 say $S0 872 .sub 'instantiate_str' 873 .const 'Float' pi = "3.1" 874 $P1 = get_class ['Float'] 875 isa_ok(pi, $P1) 876 is(pi, 3.1, 'instantiate_str', PRECISION) 877 .end 1360 878 1361 $P2 = new ['Float'] 1362 $P2 = 0.5 1363 $P3 = $P2.'ln'() 1364 array[0] = $P2 1365 array[1] = $P3 1366 $S0 = sprintf "ln(%.1f) is %.9f", array 1367 say $S0 879 .sub 'cmp_subclasses' 880 $P0 = subclass 'Float', 'Flt' 881 882 $P1 = new ['Flt'] 883 $P1 = 1.5 884 885 $P2 = new ['Flt'] 886 $P2 = 2.73 887 888 $I0 = cmp $P1, $P2 889 is(1, $I0, 'cmp functions for subclasses (lt)') 890 891 $I0 = cmp $P1, $P1 892 is(0, $I0, 'cmp functions for subclasses (eq)') 893 894 $I0 = cmp $P2, $P1 895 is(1, $I0, 'cmp functions for subclasses (gt)') 1368 896 .end 1369 CODE1370 ln(45.0) is 3.8066624901371 ln(0.5) is 0.6931471811372 OUTPUT1373 897 1374 pir_output_is( <<'CODE', <<'OUTPUT', 'log10 as a method' ); 1375 .include 'fp_equality.pasm' 1376 .sub main :main 898 .sub 'test_method' 899 .param string method 900 .param num number 901 .param num expected 902 1377 903 .local pmc array 1378 array = new 'FixedFloatArray' 1379 array = 2 904 array = new 'FixedPMCArray' 905 array = 3 906 array[0] = method 907 array[1] = number 908 array[2] = expected 909 1380 910 $P0 = new ['Float'] 1381 $P0 = 1000.0 1382 $P1 = $P0.'log10'() 1383 array[0] = $P0 1384 array[1] = $P1 1385 $S0 = sprintf "log10(%.1f) is %.9f", array 1386 say $S0 911 $P0 = number 912 $P1 = $P0.method() 1387 913 1388 $P2 = new ['Float'] 1389 $P2 = 0.5 1390 $P3 = $P2.'log10'() 1391 array[0] = $P2 1392 array[1] = $P3 1393 $S0 = sprintf "log10(%.1f) is %.9f", array 1394 say $S0 914 $S0 = sprintf '%s(%.1f) is %.9f', array 915 is($P1, expected, $S0, PRECISION) 1395 916 .end 1396 CODE1397 log10(1000.0) is 3.0000000001398 log10(0.5) is 0.3010299961399 OUTPUT1400 917 1401 pir_output_is( <<'CODE', <<'OUTPUT', 'log2 as a method' ); 1402 .include 'fp_equality.pasm' 1403 .sub main :main 1404 .local pmc array 1405 array = new 'FixedFloatArray' 1406 array = 2 1407 $P0 = new ['Float'] 1408 $P0 = 32.0 1409 $P1 = $P0.'log2'() 1410 array[0] = $P0 1411 array[1] = $P1 1412 $S0 = sprintf "log2(%.1f) is %.9f", array 1413 say $S0 918 .sub 'acos_method' 919 test_method('acos', 0.0, 1.570796327) 920 test_method('acos', 0.5, 1.047197551) 921 .end 1414 922 1415 $P2 = new ['Float'] 1416 $P2 = 0.5 1417 $P3 = $P2.'log2'() 1418 array[0] = $P2 1419 array[1] = $P3 1420 $S0 = sprintf "log2(%.1f) is %.9f", array 1421 say $S0 923 .sub 'cos_method' 924 test_method('cos', 0.0, 1.0) 925 test_method('cos', 0.5, 0.877582562) 1422 926 .end 1423 CODE1424 log2(32.0) is 5.0000000001425 log2(0.5) is 1.0000000001426 OUTPUT1427 927 1428 pir_output_is( <<'CODE', <<'OUTPUT', 'sec as a method' ); 1429 .include 'fp_equality.pasm' 1430 .sub main :main 1431 .local pmc array 1432 array = new 'FixedFloatArray' 1433 array = 2 1434 $P0 = new ['Float'] 1435 $P0 = 0.0 1436 $P1 = $P0.'sec'() 1437 array[0] = $P0 1438 array[1] = $P1 1439 $S0 = sprintf "sec(%.1f) is %.9f", array 1440 say $S0 928 .sub 'asec_method' 929 test_method('asec', 1.0, 0.0) 930 test_method('asec', 3.0, 1.230959417) 931 .end 1441 932 1442 $P2 = new ['Float'] 1443 $P2 = 0.5 1444 $P3 = $P2.'sec'() 1445 array[0] = $P2 1446 array[1] = $P3 1447 $S0 = sprintf "sec(%.1f) is %.9f", array 1448 say $S0 933 .sub 'asin_method' 934 test_method('asin', 0.0, 0.0) 935 test_method('asin', 0.5, 0.523598776) 1449 936 .end 1450 CODE1451 sec(0.0) is 1.0000000001452 sec(0.5) is 1.1394939271453 OUTPUT1454 937 1455 pir_output_is( <<'CODE', <<'OUTPUT', 'sech as a method' ); 1456 .include 'fp_equality.pasm' 1457 .sub main :main 1458 .local pmc array 1459 array = new 'FixedFloatArray' 1460 array = 2 938 .sub 'atan_method' 939 test_method('atan', 0.0, 0.0) 940 test_method('atan', 0.5, 0.463647609) 941 .end 942 943 .sub 'atan2_method' 1461 944 $P0 = new ['Float'] 1462 $P0 = 0.0 1463 $P1 = $P0.'sech'() 1464 array[0] = $P0 1465 array[1] = $P1 1466 $S0 = sprintf "sech(%.1f) is %.9f", array 1467 say $S0 945 $P1 = new ['Float'] 1468 946 1469 $P2 = new ['Float'] 1470 $P2 = 0.5 1471 $P3 = $P2.'sech'() 1472 array[0] = $P2 1473 array[1] = $P3 1474 $S0 = sprintf "sech(%.1f) is %.9f", array 1475 say $S0 947 $P0 = 0.7 948 $P1 = 0.5 949 950 $P2 = $P0.'atan2'($P1) 951 is($P2, 0.950546841, 'atan2 as a method', PRECISION) 1476 952 .end 1477 CODE1478 sech(0.0) is 1.0000000001479 sech(0.5) is 0.8868188841480 OUTPUT1481 953 1482 pir_output_is( <<'CODE', <<'OUTPUT', 'sin as a method' ); 1483 .include 'fp_equality.pasm' 1484 .sub main :main 1485 .local pmc array 1486 array = new 'FixedFloatArray' 1487 array = 2 1488 $P0 = new ['Float'] 1489 $P0 = 0.0 1490 $P1 = $P0.'sin'() 1491 array[0] = $P0 1492 array[1] = $P1 1493 $S0 = sprintf "sin(%.1f) is %.9f", array 1494 say $S0 954 .sub 'cosh_method' 955 test_method('cosh', 0.0, 1.0) 956 test_method('cosh', 0.5, 1.127625965) 957 .end 1495 958 1496 $P2 = new ['Float'] 1497 $P2 = 0.5 1498 $P3 = $P2.'sin'() 1499 array[0] = $P2 1500 array[1] = $P3 1501 $S0 = sprintf "sin(%.1f) is %.9f", array 1502 say $S0 959 .sub 'exp_method' 960 test_method('exp', 0.0, 1.0) 961 test_method('exp', 0.5, 1.648721271) 1503 962 .end 1504 CODE1505 sin(0.0) is 0.0000000001506 sin(0.5) is 0.4794255391507 OUTPUT1508 963 1509 pir_output_is( <<'CODE', <<'OUTPUT', 'sinh as a method' ); 1510 .include 'fp_equality.pasm' 1511 .sub main :main 1512 .local pmc array 1513 array = new 'FixedFloatArray' 1514 array = 2 1515 $P0 = new ['Float'] 1516 $P0 = 0.0 1517 $P1 = $P0.'sinh'() 1518 array[0] = $P0 1519 array[1] = $P1 1520 $S0 = sprintf "sinh(%.1f) is %.9f", array 1521 say $S0 964 .sub 'ln_method' 965 test_method('ln', 1.0, 0.0) 966 test_method('ln', 45.0, 3.806662490) 967 test_method('ln', 0.5, 0.693147181) 968 .end 1522 969 1523 $P2 = new ['Float'] 1524 $P2 = 0.5 1525 $P3 = $P2.'sinh'() 1526 array[0] = $P2 1527 array[1] = $P3 1528 $S0 = sprintf "sinh(%.1f) is %.9f", array 1529 say $S0 970 .sub 'log10_method' 971 test_method('log10', 1000.0, 3.0) 972 test_method('log10', 0.5, 0.301029996) 1530 973 .end 1531 CODE1532 sinh(0.0) is 0.0000000001533 sinh(0.5) is 0.5210953051534 OUTPUT1535 974 1536 pir_output_is( <<'CODE', <<'OUTPUT', 'tan as a method' ); 1537 .include 'fp_equality.pasm' 1538 .sub main :main 1539 .local pmc array 1540 array = new 'FixedFloatArray' 1541 array = 2 1542 $P0 = new ['Float'] 1543 $P0 = 0.0 1544 $P1 = $P0.'tan'() 1545 array[0] = $P0 1546 array[1] = $P1 1547 $S0 = sprintf "tan(%.1f) is %.9f", array 1548 say $S0 975 .sub 'log2_method' 976 test_method('log2', 32.0, 5.0) 977 test_method('log2', 0.5, 1.0) 978 .end 1549 979 1550 $P2 = new ['Float'] 1551 $P2 = 0.5 1552 $P3 = $P2.'tan'() 1553 array[0] = $P2 1554 array[1] = $P3 1555 $S0 = sprintf "tan(%.1f) is %.9f", array 1556 say $S0 980 .sub 'sec_method' 981 test_method('sec', 0.0, 1.0) 982 test_method('sec', 0.5, 1.139493927) 1557 983 .end 1558 CODE1559 tan(0.0) is 0.0000000001560 tan(0.5) is 0.5463024901561 OUTPUT1562 984 1563 pir_output_is( <<'CODE', <<'OUTPUT', 'tanh as a method' ); 1564 .include 'fp_equality.pasm' 1565 .sub main :main 1566 .local pmc array 1567 array = new 'FixedFloatArray' 1568 array = 2 1569 $P0 = new ['Float'] 1570 $P0 = 0.0 1571 $P1 = $P0.'tanh'() 1572 array[0] = $P0 1573 array[1] = $P1 1574 $S0 = sprintf "tanh(%.1f) is %.9f", array 1575 say $S0 985 .sub 'sech_method' 986 test_method('sech', 0.0, 1.0) 987 test_method('sech', 0.5, 0.886818884) 988 .end 1576 989 1577 $P2 = new ['Float'] 1578 $P2 = 0.5 1579 $P3 = $P2.'tanh'() 1580 array[0] = $P2 1581 array[1] = $P3 1582 $S0 = sprintf "tanh(%.1f) is %.9f", array 1583 say $S0 990 .sub 'sin_method' 991 test_method('sin', 0.0, 0.0) 992 test_method('sin', 0.5, 0.479425539) 1584 993 .end 1585 CODE1586 tanh(0.0) is 0.0000000001587 tanh(0.5) is 0.4621171571588 OUTPUT1589 994 1590 pir_output_is( <<'CODE', <<'OUTPUT', 'sqrt as a method' ); 1591 .include 'fp_equality.pasm' 1592 .sub main :main 1593 .local pmc array 1594 array = new 'FixedFloatArray' 1595 array = 2 1596 $P0 = new ['Float'] 1597 $P0 = 16.0 1598 $P1 = $P0.'sqrt'() 1599 array[0] = $P0 1600 array[1] = $P1 1601 $S0 = sprintf "sqrt(%.1f) is %.9f", array 1602 say $S0 995 .sub 'sinh_method' 996 test_method('sinh', 0.0, 0.0) 997 test_method('sinh', 0.5, 0.521095305) 998 .end 1603 999 1604 $P2 = new ['Float'] 1605 $P2 = 2.0 1606 $P3 = $P2.'sqrt'() 1607 array[0] = $P2 1608 array[1] = $P3 1609 $S0 = sprintf "sqrt(%.1f) is %.9f", array 1610 say $S0 1000 .sub 'tan_method' 1001 test_method('tan', 0.0, 0.0) 1002 test_method('tan', 0.5, 0.546302490) 1611 1003 .end 1612 CODE1613 sqrt(16.0) is 4.0000000001614 sqrt(2.0) is 1.4142135621615 OUTPUT1616 1004 1005 .sub 'tanh_method' 1006 test_method('tanh', 0.0, 0.0) 1007 test_method('tanh', 0.5, 0.462117157) 1008 .end 1617 1009 1010 .sub 'sqrt_method' 1011 test_method('sqrt', 16.0, 4.0) 1012 test_method('sqrt', 2.0, 1.414213562) 1013 .end 1014 1618 1015 # Local Variables: 1619 # mode: cperl 1620 # cperlindentlevel: 4 1016 # mode: pir 1621 1017 # fillcolumn: 100 1622 1018 # End: 1623 # vim: expandtab shiftwidth=4 :1019 # vim: expandtab shiftwidth=4 ft=pir: