Fix JS number rounding on x87#1244
Conversation
saghul
left a comment
There was a problem hiding this comment.
I'm not going to pretend to understand what's going on here 😅
Which I guess makes sense because git isn't part of build-base but then how the heck do other jobs pass? Anyway, I'll add it and let's see how it goes. |
Disable 80-bits extended precision, use standard 64-bits precision. The extra precision affects rounding and is user-observable, meaning it causes test262 tests to fail. The rounding mode is a per-CPU (or, more accurately, per-FPU) property, and since quickjs is often used as a library, take care to tweak the FPU control word before sensitive operations, and restore it afterwards. Only affects x87. SSE is IEEE-754 conforming. Fixes: quickjs-ng#1236
The x87 coprocessor has a register that controls various options, like rounding, exceptions, etc. Its floating-point registers are 80 bits wide, which is good if you want extra precision, but bad if you want strict IEEE-754 conformance. I made it turn off the extra precision while we add/subtract/etc., then restore the coprocessor to its original state, so we don't affect other parts of the (embedder's) program, that may depend on that extra precision. |
Today in "learning stuff with Ben"! Thank you, TIL! |
Disable 80-bits extended precision, use standard 64-bits precision. The extra precision affects rounding and is user-observable, meaning it causes test262 tests to fail.
The rounding mode is a per-CPU (or, more accurately, per-FPU) property, and since quickjs is often used as a library, take care to tweak the FPU control word before sensitive operations, and restore it afterwards.
Only affects x87. SSE is IEEE-754 conforming.
Fixes: #1236
(new CI job can fail, may need to link explicitly to libm)