# New Ticket Created by Lars Balker Rasmussen
# Please include the string: [perl #24868]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=24868 >
I have added floor and ceil ops (like I did for floor in september,
but noone noticed).
--
Lars Balker Rasmussen Consult::Perl
Index: ops/math.ops
===================================================================
RCS file: /cvs/public/parrot/ops/math.ops,v
retrieving revision 1.11
diff -u -a -r1.11 math.ops
--- ops/math.ops 23 Oct 2003 17:41:55 -0000 1.11
+++ ops/math.ops 10 Jan 2004 21:59:25 -0000
@@ -413,6 +413,64 @@
########################################
+=item B<ceil>(inout NUM)
+
+Set $1 to the smallest integral value greater than or equal to $1.
+
+=item B<ceil>(out INT, in NUM)
+
+=item B<ceil>(out NUM, in NUM)
+
+Set $1 to the smallest integral value greater than or equal to $2.
+
+=cut
+
+inline op ceil(inout NUM) {
+ $1 = ceil( $1 );
+ goto NEXT();
+}
+
+inline op ceil(out INT, in NUM) {
+ $1 = (INTVAL)ceil($2);
+ goto NEXT();
+}
+
+inline op ceil(out NUM, in NUM) {
+ $1 = ceil($2);
+ goto NEXT();
+}
+
+########################################
+
+=item B<floor>(inout NUM)
+
+Set $1 to the largest integral value less than or equal to $1.
+
+=item B<floor>(out INT, in NUM)
+
+=item B<floor>(out NUM, in NUM)
+
+Set $1 to the largest integral value less than or equal to $2.
+
+=cut
+
+inline op floor(inout NUM) {
+ $1 = floor( $1 );
+ goto NEXT();
+}
+
+inline op floor(out INT, in NUM) {
+ $1 = (INTVAL)floor($2);
+ goto NEXT();
+}
+
+inline op floor(out NUM, in NUM) {
+ $1 = floor($2);
+ goto NEXT();
+}
+
+########################################
+
=item B<inc>(inout INT)
=item B<inc>(inout NUM)
Index: t/op/arithmetics.t
===================================================================
RCS file: /cvs/public/parrot/t/op/arithmetics.t,v
retrieving revision 1.7
diff -u -a -r1.7 arithmetics.t
--- t/op/arithmetics.t 11 Sep 2003 14:48:51 -0000 1.7
+++ t/op/arithmetics.t 10 Jan 2004 21:59:26 -0000
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 18;
+use Parrot::Test tests => 20;
use Test::More;
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -281,6 +281,142 @@
0.000000
123.456789
123.456789
+OUTPUT
+
+output_is(<<'CODE', <<OUTPUT, "ceil of a native number");
+ set N0, 0
+ ceil N0
+ print N0
+ print "\n"
+ set N0, 123.45678901
+ ceil N0
+ print N0
+ print "\n"
+ set N0, -123.45678901
+ ceil N0
+ print N0
+ print "\n"
+ set N0, 0
+ set N1, 1
+ ceil N1, N0
+ print N1
+ print "\n"
+ set N0, 0.0
+ set N1, 1
+ ceil N1, N0
+ print N1
+ print "\n"
+ set N0, 123.45678901
+ set N1, 1
+ ceil N1, N0
+ print N1
+ print "\n"
+ set N0, -123.45678901
+ set N1, 1
+ ceil N1, N0
+ print N1
+ print "\n"
+ set N0, 0
+ set I1, 1
+ ceil I1, N0
+ print I1
+ print "\n"
+ set N0, 0.0
+ set I1, 1
+ ceil I1, N0
+ print I1
+ print "\n"
+ set N0, 123.45678901
+ set I1, 1
+ ceil I1, N0
+ print I1
+ print "\n"
+ set N0, -123.45678901
+ set I1, 1
+ ceil I1, N0
+ print I1
+ print "\n"
+ end
+CODE
+0.000000
+124.000000
+-123.000000
+0.000000
+0.000000
+124.000000
+-123.000000
+0
+0
+124
+-123
+OUTPUT
+
+output_is(<<'CODE', <<OUTPUT, "floor of a native number");
+ set N0, 0
+ floor N0
+ print N0
+ print "\n"
+ set N0, 123.45678901
+ floor N0
+ print N0
+ print "\n"
+ set N0, -123.45678901
+ floor N0
+ print N0
+ print "\n"
+ set N0, 0
+ set N1, 1
+ floor N1, N0
+ print N1
+ print "\n"
+ set N0, 0.0
+ set N1, 1
+ floor N1, N0
+ print N1
+ print "\n"
+ set N0, 123.45678901
+ set N1, 1
+ floor N1, N0
+ print N1
+ print "\n"
+ set N0, -123.45678901
+ set N1, 1
+ floor N1, N0
+ print N1
+ print "\n"
+ set N0, 0
+ set I1, 1
+ floor I1, N0
+ print I1
+ print "\n"
+ set N0, 0.0
+ set I1, 1
+ floor I1, N0
+ print I1
+ print "\n"
+ set N0, 123.45678901
+ set I1, 1
+ floor I1, N0
+ print I1
+ print "\n"
+ set N0, -123.45678901
+ set I1, 1
+ floor I1, N0
+ print I1
+ print "\n"
+ end
+CODE
+0.000000
+123.000000
+-124.000000
+0.000000
+0.000000
+123.000000
+-124.000000
+0
+0
+123
+-124
OUTPUT
#