I'd like some abs ops so I can make the fp tests better, does the attached patch do the right thing? I'll commit tomorrow if no one complains.
Alex Gough -- http://users.ox.ac.uk/~shug0957/
Index: core.ops =================================================================== RCS file: /home/perlcvs/parrot/core.ops,v retrieving revision 1.33 diff -u -r1.33 core.ops --- core.ops 2001/11/29 04:25:02 1.33 +++ core.ops 2001/11/29 18:36:41 @@ -739,6 +739,22 @@ ######################################## +=item B<abs>(i|n, i|ic|n|nc) + +Set $1 to absolute value of $2. + +=cut + +AUTO_OP abs(i, i|ic|n|nc) { + $1 = (INTVAL)labs((INTVAL)$2); +} + +AUTO_OP abs(n, n|nc|i|ic) { + $1 = (FLOATVAL)fabs((FLOATVAL)$2); +} + +######################################## + =item B<cmod>(i, i, i) =item B<cmod>(i, i, ic) Index: t/op/integer.t =================================================================== RCS file: /home/perlcvs/parrot/t/op/integer.t,v retrieving revision 1.13 diff -u -r1.13 integer.t --- t/op/integer.t 2001/10/14 00:43:50 1.13 +++ t/op/integer.t 2001/11/29 18:36:41 @@ -1,6 +1,6 @@ #! perl -w -use Parrot::Test tests => 27; +use Parrot::Test tests => 28; output_is(<<CODE, <<OUTPUT, "set_i_ic"); # XXX: Need a test for writing outside the set of available @@ -169,6 +169,25 @@ 574908040 862362060 1724724120 +OUTPUT + +output_is(<<'CODE', <<'OUTPUT', "abs(i, i|ic)"); + set I0, 1 + abs I1, -1 + abs I0, I0 + set I2, -1 + abs I2, I2 + print I0 + print "\n" + print I1 + print "\n" + print I2 + print "\n" + end +CODE +1 +1 +1 OUTPUT output_is(<<CODE, <<OUTPUT, "sub_i"); Index: t/op/number.t =================================================================== RCS file: /home/perlcvs/parrot/t/op/number.t,v retrieving revision 1.9 diff -u -r1.9 number.t --- t/op/number.t 2001/10/14 00:43:50 1.9 +++ t/op/number.t 2001/11/29 18:36:42 @@ -1,6 +1,6 @@ #! perl -w -use Parrot::Test tests => 27; +use Parrot::Test tests => 28; output_is(<<CODE, <<OUTPUT, "set_n_nc"); set N0, 1.0 @@ -151,6 +151,29 @@ end CODE 420042.000000 +OUTPUT + +output_is(<<'CODE', <<'OUTPUT', "abs(n, i|ic|n|nc)"); + set I0, -1 + abs N0, I0 + abs N1, -1 + set N2, -1 + abs N2, N2 + abs N3, -1.0 + print N0 + print "\n" + print N1 + print "\n" + print N2 + print "\n" + print N3 + print "\n" + end +CODE +1.000000 +1.000000 +1.000000 +1.000000 OUTPUT output_is(<<CODE, <<OUTPUT, "mul_i");