JavaScript already handles -0 well in mathematical functions (but not in
strings!):
Strings? Don't use non-e.r. operators (==, !=) or relationals with
mixed-type operands. That's just off the Math map.
I wouldn't dream of it. JavaScript's problem with -0 in string conversion
leads to several anomalies. And it does not conform to IEEE754 (as every
machine does these days).
Stylistically:
(-0).toFixed(0) -> "0"
but
(-Number.MIN_VALUE).toFixed(0) -> "-0"
Numerically, with single-element Arrays:
+[-0] -> 0
but
+[-1] -> -1
Of course
+(-0) -> -0
Also -0 is not preserved in a JSON string, even though JSON syntax allows
it. Thus simply by transferring data in JSON (without any funny business)
one risks an analytical error:
JSON.stringify({x: -0}) -> "{"x":0}"
As I said earlier: most people don't care about -0, but it is important in
Analysis for:
1) branch cuts
2) reflectional symmetry (consider laminar flow at a leading edge).
Before the numerical analysts at IEEE sorted it out, improper -0 was a
common mistake in CAD systems since one of the flow lines goes missing,
breaking symmetry and failing to establish a boundary.
See http://en.wikipedia.org/wiki/Signed_zero
Would it hurt to do -0 string conversion right? I can't imagine anyone is
relying on the current behaviour. I guess this would require a change in
the internal toString function, plus changes to Number.prototype.toString
and Number.prototype.to****
As for IEEE754 conformance: so near and yet so far ...
Guy Steele helped us sort this out in ES1 days.
Math.atan2(+/-0, +/-0) also has the right sign for the {+/-0, +/-Math.PI}
results.
Also 1/-0 == -Infinity. And quite right too.
Indeed, JavaScript's mathematical and arithmetic handling of -0 is perfect,
and conforms to IEEE754. Much respect and no complaints here. I have
checked every ES5 Math function.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss