3 ms·
The 42 comes from the article itself. Both solutions make sense... the blog post refers to a ieee<->integer representation hack that likely finds answers faste
by syncsynchalt 6y ago
The 42 comes from the article itself.
Both solutions make sense... the blog post refers to a ieee<->integer representation hack that likely finds answers faster, because it more quickly finds the values that tend to be in realistic numbers. It works by doing a binary search of all possible values representable in floating point (of which there are more for smaller numbers, due to the design tradeoff of IEEE floating point).
The TruffleRuby binary search solution is also "correct" in its own way, in that it's binary searching using the actual floating point values themselves.
- croes 6y agoI doubt that 42.0 > 42
- syncsynchalt 6y agoThat's the list of checks made by the bsearch algorithm. It will have to do at least one check near the end that's <= 42.0. EDIT: It will also be probing to the ULP level, which the print could be rounding to 42.0. That could explain why there are at least two checks of "42.0".