[chuck-users] negative zero
Robert Poor
rdpoor at gmail.com
Sat Feb 28 16:10:31 EST 2009
I'm troubled by ChucK's handling of negative zero. A variable set to
-0.0 is indistinguishable from a variable set to 0.0, except in
printing. This is not a problem in everyday practice, but it seems
likely that it will cause trouble when you pass to an external program.
[Why would you set a variable to -0.0 in the first place? Try this:
(-3.0 % 1.0) => float bar;]
Comments?
====================
0.0 => float foo;
-0.0 => float bar;
// even though foo and bar print differently...
<<< "foo = ", foo, " bar = ", bar >>>;
// in ChucK's eyes, they are both considered to be zero...
<<< "sgn(foo) = ", Std.sgn(foo), " sgn(bar) = ", Std.sgn(bar) >>>;
// and they are equal...
if (foo == bar) {
<<< "equal" >>>;
}
====================
produces
====================
% chuck test.ck
foo = 0.000000 bar = -0.000000
sgn(foo) = 0.000000 sgn(bar) = 0.000000
"equal" : (string)
====================
More information about the chuck-users
mailing list