Bug 187650
Summary: | Number.toPrecision returns a wrong value | ||
---|---|---|---|
Product: | WebKit | Reporter: | isol2 |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED WONTFIX | ||
Severity: | Normal | CC: | ashvayka |
Priority: | P2 | ||
Version: | Safari 11 | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
isol2
Version: JavaScriptCore v233804
OS: Ubuntu 16.04 x64
Hi everyone,
I found an issue on a test case using Number.toPrecision that I don’t know if it is considered as an incompatibility issue between engines or a real bug example, but according with ES6 specs some values are described as "approximately" maybe this is a case of it.
V8, JSC and SpiderMonkey returns the wrong value if param > 17, only Chakra works as expected.
Steps to reproduce:
print(123.56.toPrecision(18) === "123.560000000000000");
print(123.56.toPrecision(18))
Actual results:
False
123.560000000000002
Expected results:
True
123.560000000000000
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Alexey Shvayka
(In reply to isol2 from comment #0)
> I found an issue on a test case using Number.toPrecision that I don’t know
> if it is considered as an incompatibility issue between engines or a real
> bug example, but according with ES6 specs some values are described as
> "approximately" maybe this is a case of it.
Thank you for report!
This is most certainly a IEEE 754 precision issue like 0.1 + 0.2 != 0.3.
The spec prose is worded to highlight the inaccuracy: please see step 10.a of https://tc39.es/ecma262/#sec-number.prototype.toprecision.