Roger Andrews wrote:
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"
Is this a bug in the spec for toFixed?
15.7.4.5 Number.prototype.toFixed (fractionDigits)
Return a String containing this Number value represented in decimal
fixed-point notation with fractionDigits digits after the decimal point.
If fractionDigits is undefined, 0 is assumed. Specifically, perform the
following steps:
1. Let f be ToInteger(fractionDigits). (If fractionDigits is undefined,
this step produces the value 0).
2. If f < 0 or f > 20, throw a RangeError exception.
3. Let x be this Number value.
4. If x is NaN, return the String "NaN".
5. Let s be the empty String.
6. If x < 0, then
a. Let s be "-".
b. Let x = –x.
Of course, in the language (-0 < 0) is false. See 5.2 Algorithm Conventions:
Mathematical operations such as addition, subtraction, negation,
multiplication, division, and the mathematical functions defined later
in this clause should always be understood as computing exact
mathematical results on mathematical real numbers, which do not include
infinities and do not include a negative zero that is distinguished from
positive zero. Algorithms in this standard that model floating-point
arithmetic include explicit steps, where necessary, to handle infinities
and signed zero and to perform rounding. If a mathematical operation or
function is applied to a floating-point number, it should be understood
as being applied to the exact mathematical value represented by that
floating-point number; such a floating-point number must be finite, and
if it is +0 or −0 then the corresponding mathematical value is simply 0.
Ouch.
Perhaps toFixed has a quirk we cannot fix at this point. I summon
Waldemar and Allen.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss