Get the latest tech news

Converting Integers to Floats Using Hyperfocus (2022)


A few years ago, due to some random chain of events, I ended up implementing a conversion from 128 bit integers to 64 bit floats. This would’ve turned out to be a complete waste of time, except that my final version is faster than the builtin conversion of every compiler I tested. In this blog post, I’ll explain what happened, how floats work, how this conversion works, and how it got a bit out of hand.

So, out of pure spite and a strong sense of needing to prove that yes I am having fun damnit!, I spent the next several days and nights angrily writing many variants of my code, determined to take revenge on Rustc, somehow. In the end I also made some architecture-specific versions, such as an implementation that makes use of native f64 addition and subtraction instructions to perform u128-to-f64 conversion another two times faster (2.3 nanoseconds), by using some tricks that could fill their own blog post. Eventually, tired but satisfied, I pushed it all to GitHub and slowly woke up from my hyperfocus fueled week-long fever dream, wondering when I had last slept or eaten.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Integers

Integers

Photo of floats

floats

Photo of hyperfocus

hyperfocus

Related news:

News photo

Four integers are enough to write a Snake Game

News photo

Most ints are not floats

News photo

Microprocessor's Romance with Integers