RESOLVED INVALID 24156
Unary + conversion to number fails for negative hexadecimal (-0xff) 0x
https://bugs.webkit.org/show_bug.cgi?id=24156
Summary Unary + conversion to number fails for negative hexadecimal (-0xff) 0x
Jorge
Reported 2009-02-25 01:47:21 PST
See: javascript:s= "0x12";alert((+s)+ ","+ parseInt(s,16)); //-> 18,18 but: javascript:s= "-0x12";alert((+s)+ ","+ parseInt(s,16)); //-> NaN,-18
Attachments
Cameron Zwarich (cpst)
Comment 1 2009-02-25 23:22:11 PST
This works as expected. See section 9.3.1 of the ECMA spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf The ToNumber operation (which is used by the unary plus operator) only handles negative signs for decimal numbers, not hex or octal. It might be a bit strange, but it's the spec.
Jorge
Comment 2 2009-02-26 01:03:21 PST
(In reply to comment #1) > > The ToNumber operation (which is used by the unary plus operator) only handles > negative signs for decimal numbers, not hex or octal. It might be a bit > strange, but it's the spec. FF, Opera and Chrome handle them fine, and that might be perceived as "better". Better than the spec -if you want- but better, after all. Now, what's the best browser ? Not Safari when it comes to hex string conversion to number... IMO, in this case better is better than the spec. Safari is doing it to/in-spec, but worse.
Cameron Zwarich (cpst)
Comment 3 2009-02-26 07:50:25 PST
If it's a potential compatibility issue down the road, then it probably makes sense to match Firefox on this.
Gavin Barraclough
Comment 4 2011-09-07 00:54:05 PDT
This was a bug in other browsers, and fixed in the latest FireFox. Behaves correctly.
Note You need to log in before you can comment on or make changes to this bug.