"Burnett, David" <[EMAIL PROTECTED]> writes:
> I asked how to 'floor' in parrot on IRC last night,  and this raised the
> the idea of having a 'floor' op. I was then asked to email a reminder here
> so here it is.

I've implemented an op for floor on native numbers.  Feel free to give
it a whirl.

(I'm not sure if floor(-0.0) is meant to return -0.0 or not, but it does.)

> So I now I have a working my perlin noise (with turbulence) implementation
> written in pure pasm :-)

Cool!  So, how does it perform? ;)
-- 
Lars Balker Rasmussen                                      Consult::Perl

Index: math.ops
===================================================================
RCS file: /cvs/public/parrot/math.ops,v
retrieving revision 1.8
diff -u -a -r1.8 math.ops
--- math.ops	31 Jul 2003 19:39:11 -0000	1.8
+++ math.ops	3 Sep 2003 17:22:51 -0000
@@ -390,6 +390,35 @@
 
 ########################################
 
+=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.6
diff -u -a -r1.6 arithmetics.t
--- t/op/arithmetics.t	8 Aug 2003 03:20:23 -0000	1.6
+++ t/op/arithmetics.t	3 Sep 2003 17:22:52 -0000
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 40;
+use Parrot::Test tests => 41;
 use Test::More;
 
 my $fp_equality_macro = <<'ENDOFMACRO';
@@ -303,7 +303,80 @@
 123.456789
 123.456789
 OUTPUT
- 
+
+output_is(<<'CODE', <<OUTPUT, "floor of a native number");
+	set N0, 0
+	floor N0
+	print N0
+	print "\n"
+	set N0, -0.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
+-0.000000
+123.000000
+-124.000000
+0.000000
+0.000000
+123.000000
+-124.000000
+0
+0
+123
+-124
+OUTPUT
+
 #
 # FLOATVAL and INTVAL tests
 #

Reply via email to