Index: t/pmc/float.t =================================================================== --- t/pmc/float.t (révision 40924) +++ t/pmc/float.t (copie de travail) @@ -1,15 +1,7 @@ -#!perl +#! parrot # Copyright (C) 2001-2009, Parrot Foundation. # $Id$ -use strict; -use warnings; -use lib qw( . lib ../lib ../../lib ); - -use Test::More; -use Parrot::Test tests => 61; -use Parrot::Config; - =head1 NAME t/pmc/float.t - Floating-point Numbers @@ -24,1600 +16,1004 @@ =cut +.const int TESTS = 159 +.const num PRECISION = 0.000001 -pasm_output_is( <<"CODE", < '-0.0 not implemented, TT #313' ) - unless $PConfig{has_negative_zero}; + $P0 = 1e8 + $P0 /= 0.5 + is($P0, 2e8, 'Basic numeric arithmetic: division (1)', PRECISION) -pasm_output_like( <<'CODE', <<'OUTPUT', 'neg 0', @todo ); - new P0, ['Float'] - set P0, 0.0 - neg P0 - print P0 - end -CODE -/^-0/ -OUTPUT -} + $P0 /= 4000.0 + is($P0, 50000.0, 'Basic numeric arithmetic: division (2)', PRECISION) +.end -pasm_output_is( << 'CODE', << 'OUTPUT', "Equality" ); - new P0, ['Float'] - set P0, 1e8 - new P1, ['Float'] - set P1, 1e8 - new P2, ['Float'] - set P2, 2.4 +.sub 'increment_decrement' + $P0 = new ['Float'] - eq P0, P1, OK1 - print "not " -OK1: print "ok 1\n" + $P0 = 0.5 + inc $P0 + is($P0, 1.5, 'increment (1)', PRECISION) + dec $P0 + is($P0, 0.5, 'decrement (1)', PRECISION) + dec $P0 + is($P0, -.5, 'decrement (2)', PRECISION) + inc $P0 + is($P0, 0.5, 'increment (2)', PRECISION) +.end - eq P0, P2, BAD2 - branch OK2 -BAD2: print "not " -OK2: print "ok 2\n" +.sub 'neg' + $P0 = new ['Float'] + $P0 = 0.5 + neg $P0 + is($P0, -0.5, 'Neg', PRECISION) - ne P0, P2, OK3 - print "not " -OK3: print "ok 3\n" + $P1 = new ['Float'] + $P1 = - $P0 + is($P1, 0.5, 'Neg is involutive', PRECISION) +.end - ne P0, P1, BAD4 - branch OK4 -BAD4: print "not " -OK4: print "ok 4\n" +.sub 'negative_zero' + load_bytecode 'config.pbc' + $P1 = _config() + $P2 = $P1['has_negative_zero'] + unless $P2 goto negative_zero_todoed - eq_num P0, P1, OK5 - print "not " -OK5: print "ok 5\n" + $P0 = new ['Float'] + $P0 = 0.0 + neg $P0 - eq_num P0, P2, BAD6 - branch OK6 -BAD6: print "not " -OK6: print "ok 6\n" + $S0 = $P0 + like($S0, '^\-0', 'negative zero') + .return () - ne_num P0, P2, OK7 - print "not " -OK7: print "ok 7\n" + negative_zero_todoed: + todo(1, '-0.0 not implemented, TT#313') +.end - ne_num P0, P1, BAD8 - branch OK8 -BAD8: print "not " -OK8: print "ok 8\n" - end -CODE -ok 1 -ok 2 -ok 3 -ok 4 -ok 5 -ok 6 -ok 7 -ok 8 -OUTPUT +.sub 'equality' + $P0 = new ['Float'] + $P0 = 1e8 -pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" ); + $P1 = new ['Float'] + $P1 = 1e8 -.sub _main + $P2 = new ['Float'] + $P2 = 2.4 + + $I0 = 1 + if $P0 == $P1 goto equality_1 + $I0 = 0 + equality_1: + ok($I0, 'equal floats') + + $I0 = 0 + if $P0 == $P2 goto equality_2 + $I0 = 1 + equality_2: + ok($I0, 'different floats are not equal') + + $I0 = 1 + if $P0 != $P2 goto equality_3 + $I0 = 0 + equality_3: + ok($I0, "different floats are different") + + $I0 = 0 + if $P0 != $P1 goto equality_4 + $I0 = 1 + equality_4: + ok($I0, "equal floats aren't different") + + $I0 = 1 + eq_num $P0, $P1, equality_5 + $I0 = 0 + equality_5: + ok($I0, "equal floats are eq_num") + + $I0 = 0 + eq_num $P0, $P2, equality_6 + $I0 = 1 + equality_6: + ok($I0, "different floats aren't eq_num") + + $I0 = 1 + ne_num $P0, $P2, equality_7 + $I0 = 0 + equality_7: + ok($I0, "different floats are ne_num") + + $I0 = 0 + ne_num $P0, $P1, equality_8 + $I0 = 1 + equality_8: + ok($I0, "equal floats aren't ne_num") +.end + +.sub 'is_interface_done' .local pmc pmc1 - pmc1 = new ['Float'] .local int bool1 - does bool1, pmc1, "scalar" - print bool1 - print "\n" - does bool1, pmc1, "float" - print bool1 - print "\n" - does bool1, pmc1, "no_interface" - print bool1 - print "\n" - end + pmc1 = new ['Float'] + + bool1 = does pmc1, "scalar" + ok(bool1, 'Float does "scalar"') + + bool1 = does pmc1, "float" + ok(bool1, 'Float does "float"') + + bool1 = does pmc1, "no_interface" + nok(bool1, 'Float does not "no_interface"') .end -CODE -1 -1 -0 -OUTPUT -pasm_output_is( << "CODE", << 'OUTPUT', "Abs" ); - .include 'fp_equality.pasm' - new P0, ['Float'] - set P0, 1.0 - abs P0 - eq P0, P0, OK1 - print P0 - print "not " -OK1: print "ok 1\\n" +.sub 'abs' + $P0 = new ['Float'] + $P0 = 1.0 + abs $P0 + is($P0, $P0, 'abs does not change positive floats') - set P0, -1.0 - abs P0 - .fp_eq_pasm(P0, 1.0, OK2) - print P0 - print "not " -OK2: print "ok 2\\n" + $P0 = -1.0 + abs $P0 + is($P0, 1.0, 'abs of -1.0', PRECISION) - new P1, ['Float'] - set P0, -5.0 - abs P1, P0 - .fp_eq_pasm(P1, 5.0, OK3) - print P1 - print "not " -OK3: print "ok 3\\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT + $P0 = -5.0 + abs $P0 + is($P0, 5.0, 'abs of -5.0', PRECISION) +.end -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: lt" ); - new P1, ['Float'] - set P1, 111.1 - set N1, P1 +.sub 'lt' + $P1 = new ['Float'] + $P1 = 111.11 + $N1 = $P1 - lt P1, 111.2, OK1 - print "not " -OK1: print "ok 1\n" + $I0 = 1 + lt $P1, 111.12, lt_1 + $I0 = 0 + lt_1: + ok($I0, 'lt ok') - lt P1, N1, BAD2 - branch OK2 -BAD2: print "not " -OK2: print "ok 2\n" + $I0 = 0 + lt $P1, $N1, lt_2 + $I0 = 1 + lt_2: + ok($I0, 'lt irreflexive') - lt P1, 111.0, BAD3 - branch OK3 -BAD3: print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT + $I0 = 0 + lt $P1, 111.0, lt_3 + $I0 = 1 + lt_3: + ok($I0, 'not lt') +.end -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: lt_num" ); - new P1, ['Float'] - set P1, 1.1 - new P2, ['Float'] - set P2, 1.2 - new P3, ['Float'] - set P3, 1.0 - new P4, ['Float'] - set P4, P1 +.sub 'lt_num' + $P1 = new ['Float'] + $P1 = 1.1 - lt_num P1, P2, OK1 - print "not " -OK1: print "ok 1\n" + $P2 = new ['Float'] + $P2 = 1.2 - lt_num P1, P4, BAD2 - branch OK2 -BAD2: print "not " -OK2: print "ok 2\n" + $P3 = new ['Float'] + $P3 = 1.0 - lt_num P1, P3, BAD3 - branch OK3 -BAD3: print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT + $P4 = new ['Float'] + $P4 = $P1 -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: le" ); - new P1, ['Float'] - set P1, 111.1 - set N1, P1 + $I0 = 1 + lt_num $P1, $P2, lt_num_1 + $I0 = 0 + lt_num_1: + ok($I0, 'lt_num true') - le P1, 111.2, OK1 - print "not " -OK1: print "ok 1\n" + $I0 = 0 + lt_num $P1, $P4, lt_num_2 + $I0 = 1 + lt_num_2: + ok($I0, 'lt_num irreflexive') - le P1, N1, OK2 - print "not " -OK2: print "ok 2\n" + $I0 = 0 + lt_num $P1, $P3, lt_num_3 + $I0 = 1 + lt_num_3: + ok($I0, 'lt_num false') +.end - le P1, 111.0, BAD3 - branch OK3 -BAD3: print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT +.sub 'le' + $P1 = new ['Float'] + $P1 = 111.1 + $N1 = $P1 -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: le_num" ); - new P1, ['Float'] - set P1, 1.1 - new P2, ['Float'] - set P2, 1.2 - new P3, ['Float'] - set P3, 1.0 - new P4, ['Float'] - set P4, P1 + $I0 = 1 + le $P1, 111.2, le_1 + $I0 = 0 + le_1: + ok($I0, 'le_p_nc') - le_num P1, P2, OK1 - print "not " -OK1: print "ok 1\n" + $I0 = 1 + le $P1, $N1, le_2 + $I0 = 0 + le_2: + ok($I0, 'le_p_n') - le_num P1, P4, OK2 - print "not " -OK2: print "ok 2\n" + $I0 = 0 + le $P1, 111.0, le_3 + $I0 = 1 + le_3: + ok($I0, 'le_p_nc false') - le_num P1, P3, BAD3 - branch OK3 -BAD3: print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT + $I0 = 1 + le $P1, $P1, le_4 + $I0 = 0 + le_4: + ok($I0, 'le reflexive') +.end -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: gt" ); - new P1, ['Float'] - set P1, 111.1 - set N1, P1 +.sub 'le_num' + $P1 = new ['Float'] + $P1 = 1.1 - gt P1, 111.2, BAD1 - branch OK1 -BAD1: print "not " -OK1: print "ok 1\n" + $P2 = new ['Float'] + $P2 = 1.2 - gt P1, N1, OK2 - branch OK2 -BAD2: print "not " -OK2: print "ok 2\n" + $P3 = new ['Float'] + $P3 = 1.0 - gt P1, 111.0, OK3 - print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT + $P4 = new ['Float'] + $P4 = $P1 -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: gt_num" ); - new P1, ['Float'] - set P1, 1.1 - new P2, ['Float'] - set P2, 1.2 - new P3, ['Float'] - set P3, 1.0 - new P4, ['Float'] - set P4, P1 + $I0 = 1 + le_num $P1, $P2, le_num_1 + $I0 = 0 + le_num_1: + ok($I0, 'le_num true') - gt_num P1, P2, BAD1 - branch OK1 -BAD1: print "not " -OK1: print "ok 1\n" + $I0 = 1 + le_num $P1, $P4, le_num_2 + $I0 = 0 + le_num_2: + ok($I0, 'le_num reflexive') - gt_num P1, P4, OK2 - branch OK2 -BAD2: print "not " -OK2: print "ok 2\n" + $I0 = 0 + le_num $P1, $P3, le_num_3 + $I0 = 1 + le_num_3: + ok($I0, 'le_num false') +.end - gt_num P1, P3, OK3 - print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT +.sub 'gt' + $P1 = new ['Float'] + $P1 = 111.1 + $N1 = $P1 -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: ge" ); - new P1, ['Float'] - set P1, 111.1 - set N1, P1 + $I0 = 0 + gt $P1, 111.2, gt_1 + $I0 = 1 + gt_1: + ok($I0, 'comparison ops: gt nok') - ge P1, 111.2, BAD1 - branch OK1 -BAD1: print "not " -OK1: print "ok 1\n" + $I0 = 1 + gt $P1, $N1, gt_2 + $I0 = 0 + gt_2: + nok($I0, 'comparison ops: gt irreflexive') - ge P1, N1, OK2 - print "not " -OK2: print "ok 2\n" + $I0 = 1 + gt $P1, 111.0, gt_3 + $I0 = 0 + gt_3: + ok($I0, 'comparison ops: gt ok') +.end - ge P1, 111.0, OK3 - print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT +.sub 'gt_num' + $P1 = new ['Float'] + $P2 = new ['Float'] + $P3 = new ['Float'] + $P4 = new ['Float'] -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: ge_num" ); - new P1, ['Float'] - set P1, 1.1 - new P2, ['Float'] - set P2, 1.2 - new P3, ['Float'] - set P3, 1.0 - new P4, ['Float'] - set P4, P1 + $P1 = 1.1 + $P2 = 1.2 + $P3 = 1.0 + $P4 = $P1 - ge_num P1, P2, BAD1 - branch OK1 -BAD1: print "not " -OK1: print "ok 1\n" + $I0 = 0 + gt_num $P1, $P2, gt_num_1 + $I0 = 1 + gt_num_1: + ok($I0, 'comparison ops: gt_num nok') - ge_num P1, P4, OK2 - print "not " -OK2: print "ok 2\n" + $I0 = 0 + gt_num $P1, $P4, gt_num_2 + $I0 = 1 + gt_num_2: + ok($I0, 'comparison ops: gt_num irreflexive') - ge_num P1, P3, OK3 - print "not " -OK3: print "ok 3\n" - end -CODE -ok 1 -ok 2 -ok 3 -OUTPUT + $I0 = 1 + gt_num $P1, $P3, gt_num_3 + $I0 = 0 + gt_num_3: + ok($I0, 'comparison ops: gt_num ok') +.end -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: cmp_p_n" ); - new P1, ['Float'] - set P1, 123.45 - set N1, 123.45 - set N2, -1.0 - set N3, 123.54 +.sub 'ge' + $P1 = new ['Float'] + $P1 = 111.1 + $N1 = $P1 - cmp I0, P1, N1 - print I0 - print "\n" - cmp I0, P1, N2 - print I0 - print "\n" - cmp I0, P1, N3 - print I0 - print "\n" - end -CODE -0 -1 --1 -OUTPUT + $I0 = 0 + ge $P1, 111.2, ge_1 + $I0 = 1 + ge_1: + ok($I0, 'comparison ops: ge nok') -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isgt" ); - new P1, ['Float'] - new P2, ['Float'] - new P3, ['Float'] - new P4, ['Integer'] - new P5, ['Integer'] - new P6, ['Float'] + $I0 = 1 + ge $P1, $N1, ge_2 + $I0 = 0 + ge_2: + ok($I0, 'comparison ops: ge reflexive') - set P1, 10.0 - set P2, 20.0 - set P3, 5.0 - set P4, 3 - set P5, 12 - set P6, 10.0 + $I0 = 1 + ge $P1, 111.0, ge_3 + $I0 = 0 + ge_3: + ok($I0, 'comparison ops: ge ok') +.end - isgt I0, P1, P2 - print I0 - print "\n" - isgt I0, P1, P1 - print I0 - print "\n" - isgt I0, P1, P3 - print I0 - print "\n" - isgt I0, P1, P4 - print I0 - print "\n" - isgt I0, P1, P5 - print I0 - print "\n" - isgt I0, P1, P6 - print I0 - print "\n" - end -CODE -0 -0 -1 -1 -0 -0 -OUTPUT +.sub 'ge_num' + $P1 = new ['Float'] + $P2 = new ['Float'] + $P3 = new ['Float'] + $P4 = new ['Float'] -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isge" ); - new P1, ['Float'] - new P2, ['Float'] - new P3, ['Float'] - new P4, ['Integer'] - new P5, ['Integer'] - new P6, ['Float'] + $P1 = 1.1 + $P2 = 1.2 + $P3 = 1.0 + $P4 = $P1 - set P1, 10.0 - set P2, 20.0 - set P3, 5.0 - set P4, 3 - set P5, 12 - set P6, 10.0 + $I0 = 0 + ge_num $P1, $P2, ge_num_1 + $I0 = 1 + ge_num_1: + ok($I0, 'comparison ops: ge_num nok') - isge I0, P1, P2 - print I0 - print "\n" - isge I0, P1, P1 - print I0 - print "\n" - isge I0, P1, P3 - print I0 - print "\n" - isge I0, P1, P4 - print I0 - print "\n" - isge I0, P1, P5 - print I0 - print "\n" - isge I0, P1, P6 - print I0 - print "\n" - end -CODE -0 -1 -1 -1 -0 -1 -OUTPUT + $I0 = 1 + ge_num $P1, $P4, ge_num_2 + $I0 = 0 + ge_num_2: + ok($I0, 'comparison ops: ge_num reflexive') -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: islt" ); - new P1, ['Float'] - new P2, ['Float'] - new P3, ['Float'] - new P4, ['Integer'] - new P5, ['Integer'] - new P6, ['Float'] + $I0 = 1 + ge_num $P1, $P3, ge_num_3 + $I0 = 0 + ge_num_3: + ok($I0, 'comparison ops: ge_num ok') +.end - set P1, 10.0 - set P2, 20.0 - set P3, 5.0 - set P4, 3 - set P5, 12 - set P6, 10.0 +.sub 'cmp_p_n' + $P1 = new ['Float'] + $P1 = 123.45 + $N1 = 123.45 + $N2 = -1.0 + $N3 = 123.54 - islt I0, P1, P2 - print I0 - print "\n" - islt I0, P1, P1 - print I0 - print "\n" - islt I0, P1, P3 - print I0 - print "\n" - islt I0, P1, P4 - print I0 - print "\n" - islt I0, P1, P5 - print I0 - print "\n" - islt I0, P1, P6 - print I0 - print "\n" - end -CODE -1 -0 -0 -0 -1 -0 -OUTPUT + $I0 = cmp $P1, $N1 + is($I0, 0, 'comparison ops: cmp_p_n: equality') -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isle" ); - new P1, ['Float'] - new P2, ['Float'] - new P3, ['Float'] - new P4, ['Integer'] - new P5, ['Integer'] - new P6, ['Float'] + $I0 = cmp $P1, $N2 + is($I0, 1, 'comparison ops: cmp_p_n: gt') - set P1, 10.0 - set P2, 20.0 - set P3, 5.0 - set P4, 3 - set P5, 12 - set P6, 10.0 + $I0 = cmp $P1, $N3 + is($I0, -1, 'comparison ops: cmp_p_n: lt') +.end - isle I0, P1, P2 - print I0 - print "\n" - isle I0, P1, P1 - print I0 - print "\n" - isle I0, P1, P3 - print I0 - print "\n" - isle I0, P1, P4 - print I0 - print "\n" - isle I0, P1, P5 - print I0 - print "\n" - isle I0, P1, P6 - print I0 - print "\n" - end -CODE -1 -1 -0 -0 -1 -1 -OUTPUT +.sub 'isgt' + $P1 = new ['Float'] + $P2 = new ['Float'] + $P3 = new ['Float'] + $P4 = new ['Integer'] + $P5 = new ['Integer'] + $P6 = new ['Float'] -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: iseq" ); - new P1, ['Float'] - new P2, ['Float'] - new P3, ['Float'] - new P4, ['Integer'] + $P1 = 10.0 + $P2 = 20.0 + $P3 = 5.0 + $P4 = 3 + $P5 = 12 + $P6 = 10.0 - set P1, 2.5 - set P2, 2.6 - set P3, 2.5 - set P4, 2 + $I0 = isgt $P1, $P2 + nok($I0, 'comparison ops: isgt nok') - iseq I0, P1, P1 - print I0 - print "\n" - iseq I0, P1, P2 - print I0 - print "\n" - iseq I0, P1, P3 - print I0 - print "\n" - iseq I0, P1, P4 - print I0 - print "\n" - end -CODE -1 -0 -1 -0 -OUTPUT + $I0 = isgt $P1, $P1 + nok($I0, 'comparison ops: isgt irreflexive') -pasm_output_is( << 'CODE', << 'OUTPUT', "comparison ops: isne" ); - new P1, ['Float'] - new P2, ['Float'] - new P3, ['Float'] - new P4, ['Integer'] + $I0 = isgt $P1, $P3 + ok($I0, 'comparison ops: isgt ok') - set P1, 2.5 - set P2, 2.6 - set P3, 2.5 - set P4, 2 + $I0 = isgt $P1, $P4 + ok($I0, 'comparison ops: isgt ok with Float and Integer') - isne I0, P1, P1 - print I0 - print "\n" - isne I0, P1, P2 - print I0 - print "\n" - isne I0, P1, P3 - print I0 - print "\n" - isne I0, P1, P4 - print I0 - print "\n" - end -CODE -0 -1 -0 -1 -OUTPUT + $I0 = isgt $P1, $P5 + nok($I0, 'comparison ops: isgt nok with Float and Integer') -pir_output_is( <<'CODE', <