Bug 93445 - getComputedStyle for `opacity` loses precision
Summary: getComputedStyle for `opacity` loses precision
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: javascript: var el = document.body; v...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-08 00:20 PDT by dhtmlkitchen@gmail.com
Modified: 2012-08-08 14:27 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dhtmlkitchen@gmail.com 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"
Comment 1 Alexey Proskuryakov 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.
Comment 2 Simon Fraser (smfr) 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".
Comment 3 dhtmlkitchen@gmail.com 2012-08-08 14:22:55 PDT
So 9.5., specified value, is out of reasonably useful?
Comment 4 dhtmlkitchen@gmail.com 2012-08-08 14:27:02 PDT
Correction: ".95", not "9.5".