-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
floats/ #8
Comments
exponent for 9.75 is just 4(10), or 100(2), where 1026 come from? |
If you check the table with exponents:
you'll see the row with 1026 matches the binary represenation of 9.75:
Another way of saying it, is that 9.75 is 1001.11 = 1.00111 × 2³, and 3 + 1023 = 1026. |
Can these be turned back into compiler built-ins? Or is there a reason not to do that? |
what a gorgeous project! I can see why you put so much time into it, lots of unholy fun here. I found that your final code is missing a bracket for the mantissa calculation and fails my tests as a result :'( let m = a + (b - (b >> 63 & !a)) >> 63; should be: let m = a + ((b - (b >> 63 & !a)) >> 63); because + has stronger precedence than >> (although I personally prefer the following:) let m = ((a) + (((b) - (((b) >> (63)) & (!a))) >> (63))); |
@lilly-lizard Oh oops. Those disappeared while editing this blog post somehow. Fixed. :) |
@SUPERCILEX Yeah, I opened a PR for the |
Haha, makes sense! |
I don´t know how I ended reading your blog on a Sunday morning but reading you gave me a great refreshing kick on how one person can share something that will speed up the work of millions. |
I'm reminded of some code that I wrote more than 30 years ago when I needed to convert a tape full of binary data from IBM VM/370 native 64-bit float to IEEE-754 64-bit float, without loss of any accuracy. The VM/370 used a base-16 exponent, and therefore (unlike IEEE-754) no implied leading 1. I could have written a FORTRAN program to dump the data in decimal format on the IBM and read it back on the target machine, but that seemed way too easy, and I was young and cocky, so I read the IBM assembler manual and got to work. I still have that code. Here's a gist of it, but good luck finding a machine that will run it: https://gist.github.com/DavidHarper/ba20799c6b72d6131f263316d53723fb |
This reminds me of dealing with the 32-bit float format about 25 years ago, when I was trying to implement as much floating-point as I could fit into a BASIC interpreter running on a PIC16C74 processor. |
Enjoyed this a lot! Once upon a time I did something similar for Java's BigInteger.doubleValue(): https://bugs.openjdk.java.net/browse/JDK-7131192. But you managed to make yours branch-free, and much smoother and more compact! Very nice. |
Converting Integers to Floats Using Hyperfocus - Mara's Blog
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 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.
https://blog.m-ou.se/floats/
The text was updated successfully, but these errors were encountered: