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) ====================
On Sat, Feb 28, 2009 at 4:10 PM, Robert Poor
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;
It's weirdness, but I can't imagine a program in any language I know of actually having trouble parsing -0.0. Steve
Steve;
It's weirdness, but I can't imagine a program in any language I know of actually having trouble parsing -0.0.
Aren't situations like this the reason why we have standards for the representation of floating point numbers? I seem to remember something like that. Ah, here it is; http://en.wikipedia.org/wiki/IEEE_754 Negative zero is a part of that standard. Sticking to that standard, even if it's slightly weird, will probably prevent issues more than cause them, I'd imagine. Yours, Kas.
Kas is exactly right, but I'm accustomed to languages that provide a test for negative zero. (On the other hand, I have yet to find compelling reason that I need to do so.) On 28 Feb 2009, at 22:02, Kassen wrote:
Steve;
It's weirdness, but I can't imagine a program in any language I know of actually having trouble parsing -0.0.
Aren't situations like this the reason why we have standards for the representation of floating point numbers? I seem to remember something like that.
Ah, here it is; http://en.wikipedia.org/wiki/IEEE_754
Negative zero is a part of that standard. Sticking to that standard, even if it's slightly weird, will probably prevent issues more than cause them, I'd imagine.
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On Sun, Mar 1, 2009 at 2:25 AM, Robert Poor
Kas is exactly right, but I'm accustomed to languages that provide a test for negative zero. (On the other hand, I have yet to find compelling reason that I need to do so.)
Keep in mind that ChucK's operators are implemented in C++, so there's likely to be a lot of similarity to how C++ handles numbers. Steve
On 28 Feb 2009, at 22:02, Kassen wrote:
Steve;
It's weirdness, but I can't imagine a program in any language I know of actually having trouble parsing -0.0.
Aren't situations like this the reason why we have standards for the representation of floating point numbers? I seem to remember something like that.
Ah, here it is; http://en.wikipedia.org/wiki/IEEE_754
Negative zero is a part of that standard. Sticking to that standard, even if it's slightly weird, will probably prevent issues more than cause them, I'd imagine.
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
Kassen
-
Robert Poor
-
Stephen Sinclair