Consistent decimal semantics
brendan at mozilla.org
Wed Sep 3 19:47:17 PDT 2008
On Aug 25, 2008, at 5:25 PM, Waldemar Horwat wrote:
> Brendan Eich wrote:
>>> - Should decimal values behave as objects (pure library
>>> implementation) or as primitives?
>>> If they behave as objects, then we'd get into situations such as
>>> 3m !=
>>> 3m in some cases and 3m == 3m in other cases. Also, -0m != 0m would
>>> be necessary. This is clearly unworkable.
>> What should be the result of (typeof 3m)?
> "decimal". It should not be "object" because it doesn't behave
> like other objects!
Clearly, you are correct (but you knew that ;-).
1. typeof x == "object" && !x => x == null.
2. typeof x == typeof y => x == y <=> x === y
3. 1.1m != 1.1 && 1.1m !== 1.1 (IEEE P754 mandates that binary floats
be convertible to decimal floats and that the result of the
conversion of 1.1 to decimal be 1.100000000000000088817841970012523m)
Therefore typeof 1.1m != "object" by 1, or else 0m could be mistaken
for null by existing code.
And typeof 1.1m != "number" by 3, given 2.
This leaves no choice but to add "decimal".
More information about the Es-discuss