RESOLVED WONTFIX 93445
getComputedStyle for `opacity` loses precision
https://bugs.webkit.org/show_bug.cgi?id=93445
Summary getComputedStyle for `opacity` loses precision
dhtmlkitchen@gmail.com
Reported 2012-08-08 00:20:49 PDT
Reading `opacity` back from `getComputedStyle` results in a value that is not the value specified. var el = document.body; el.style.opacity = '0.95'; // Specified value. el.style.opacity;// Specified value returned. "0.95" getComputedStyle(el).opacity; // Not the specified value. "0.949999988079071" With getComputedStyle(el).opacity, an internal number of the opacity is returned. Is it that '9.5' sets the opacity as a (lossy) binary number, which, when returned, is converted to a string? Css3 spec says that the value returned must be "The same as the specified value after clipping the <alphavalue> to the range [0.0,1.0]." Since the value returned ("0.949999988079071") is not the specified value ("9.5"), then this is a violation of a spec. http://www.w3.org/TR/css3-color/#transparency | Computed value: The same as the specified value | after clipping the <alphavalue> to the range [0.0,1.0]. Version 5.1.1 (6534.51.22) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22"
Attachments
Alexey Proskuryakov
Comment 1 2012-08-08 10:36:41 PDT
> Is it that '9.5' sets the opacity as a (lossy) binary number, which, when returned, is converted to a string? Yes. As such, this really is the specified value, and no specs have been violated. But perhaps there is something to do here that would swipe this under the carpet (like switching from float to double?), or something else I'm unaware of. So, keeping the bug open for experts to consider.
Simon Fraser (smfr)
Comment 2 2012-08-08 11:34:11 PDT
I think some floating point rounding is acceptable, so I don't think this is a bug. <http://dev.w3.org/csswg/css3-values/#numeric-types> says "UAs should support reasonably useful ranges and precisions".
dhtmlkitchen@gmail.com
Comment 3 2012-08-08 14:22:55 PDT
So 9.5., specified value, is out of reasonably useful?
dhtmlkitchen@gmail.com
Comment 4 2012-08-08 14:27:02 PDT
Correction: ".95", not "9.5".
Note You need to log in before you can comment on or make changes to this bug.