Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Floating point modulus



On Jan 11,  8:25pm, Peter Stephenson wrote:
}
} I'll leave that to you, but instead of an explicit rounding you could do
} basically the same calculation but assigned to a variable declared as an
} integer and output that.

Hm.  This seems like a bug:

% integer rnd
% print -- $(( rnd = ((29.1 % 13.0 * 10) + 0.5) ))
31.500000000000014

Shouldn't the result of the $(( ... )) be an integer because rnd has been
declared as an integer?

I had to do this instead:

diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 59d182a..8da17f7 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -18,6 +18,12 @@
 0:basic floating point arithmetic
 >31415.
 
+  integer rnd
+  (( rnd = ((29.1 % 13.0 * 10) + 0.5) ))
+  print $rnd
+0:Test floating point modulo function
+>31
+
   print $(( 0x10 + 0X01 + 2#1010 ))
 0:base input
 >27

-- 
Barton E. Schaefer



Messages sorted by: Reverse Date, Date, Thread, Author