Closed Bug 901092 Opened 11 years ago Closed 11 years ago

IonMonkey: Fold ToFloat32(ToDouble(x)) into x, when x is already a Float

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 888109

People

(Reporter: bbouvier, Unassigned)

References

Details

If x is a Float32, it seems like ToFloat32(ToDouble(x)) == x, as we never lose precision during the process. As we need to be cautious with this kind of optimizations, I have been running a C++ program in background that tries to find a float value which doesn't verify this condition. If the program doesn't find anything in a reasonable amount of time and nobody has any objections against it, I'll implement it.
The structure of single- and double-precision IEEE-754 floating point values is such that single-precision is strictly a subset of double-precision. The only slight exception is that NaN values, where the exact bit pattern matters, won't roundtrip. But it *is* the case that any NaN float will convert to a NaN double, and that will convert to a NaN float, even if the start and end values don't have the same bit patterns.
Or (based on the proof of the float/double commutative property of addition [1]): x = x+0 = ToFloat32(ToDouble(x) + ToDouble(0)) = ToFloat32(ToDouble(x)) [1] http://dl.acm.org/citation.cfm?id=221334
x = x-0, you mean. -0 + 0 is +0. :-) Good ol' IEEE-754! http://goodolcharliebrown.tumblr.com/post/420445025
Depends on: 888109
As the mir patch wasn't reviewed in bug 888109, I just wrote this two lines patch there.
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
Assignee: bugzilla → nobody
You need to log in before you can comment on or make changes to this bug.