w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.5k stars 666 forks source link

[cssom] Should <number> be serialized using scientific notation? #3276

Open BorisChiou opened 6 years ago

BorisChiou commented 6 years ago

In [1], the serialization of scientific notation for <number>, it says:

A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible, using "." to separate decimals (if any), rounding the value if necessary to not produce more than 6 decimals, preceded by "-" (U+002D) if it is negative.

Note: scientific notation is not used.

I think this is a little bit ambiguous for scientific notation. For a very long number, like a max float (3.40282e+38), all the browsers (i.e. Chrome, Firefox, Safari) still serialize the scientific notation. e.g.

div {
  animation-timing-function: cubic-bezier(0, 3.40282e+38, 0, 0);
}
console.log(window.getComputedStyle(div).animationTimingFunction); // the output is "cubic-bezier(0, 3.40282e+38, 0, 0)" in all the browsers.

Just want to know should we update the spec or all the implementations of browser are incorrect? Besides, if we want to update the spec, should we use "+" sign in scientific notation? (i.e. Use 3.40282e38, instead of 3.40282e+38, because shorter serialization is preferred.)

[1] https://drafts.csswg.org/cssom/#serializing-css-values

upsuper commented 6 years ago

(Please don't post a nonsense then edit it to a real issue, because GitHub doesn't send edited version to email notifications, and thus this kind of behavior may cause confusion to people reading emails first. If you open an issue bug forget to fill the description, just close it and open a new one. If you are going to add any nontrivial information, please use comment, or comment then remove. This would also give the information a chance to be backed up in W3C-hosting mailing list.)

BorisChiou commented 6 years ago

Sorry for this. I didn't notice the problem of W3C mailing list.

ewilligers commented 5 years ago

For example, flex-grow / flex-shrink in Firefox:

document.body.style.flexGrow = "6.78e+8";
document.body.style.flexGrow // "678000000"
getComputedStyle(document.body).flexGrow // "6.78e+8" 
upsuper commented 5 years ago

That's probably because gCS result here is serialized by C++ code, while specified value is by Servo. Maybe at some point we can solely use the Rust code and remove the C++ one...