E

Exploring Binary

exploringbinary.com · Personal blog · on HN since 2009

Exploring Binary is Rick Regan's site on binary, decimal, and floating-point arithmetic, including bugs in number conversion code.

What HN saysCommenters name it a favorite site for explaining floating-point, and link it for why 0.1 isn't exact and for decimal-to-float conversion.
34HN people shared it
20linked it in comments
48stories submitted
940story points
11 months agolast shared
2009people per year2026

Most-shared posts

  1. 1
    Java Hangs When Converting 2.2250738585072012e-308
    6 people · 180 points · first shared 2011 · 66 comments on HN
  2. 2
    PHP 5.3.3 hangs on numeric value 2.2250738585072011e-308
    5 people · 179 points · first shared 2011 · 93 comments on HN
  3. 3
    Why 0.1 Does Not Exist In Floating-Point
    4 people · 62 points · first shared 2012 · 33 comments on HN
  4. 4
    A Closer Look at the Java 2.2250738585072012e-308 Bug
    3 people · 58 points · first shared 2011 · 12 comments on HN
  5. 5
    Ten Ways to Check if an Integer Is a Power Of Two in C
    2 people · 120 points · first shared 2011 · 73 comments on HN
  6. 6
    How I Taught Third Graders Binary Numbers
    2 people · 95 points · first shared 2011 · 11 comments on HN
  7. 7
    The Spacing of Binary Floating-Point Numbers
    2 people · 41 points · first shared 2015 · 14 comments on HN
  8. 8
    Correct Decimal To Floating-Point Using Big Integers
    2 people · 20 points · first shared 2011 · discussion on HN
  9. 9
    The Shortest Decimal String That Round-Trips
    2 people · 2 points · first shared 2013 · discussion on HN
  10. 10
    How strtod() Works (and Sometimes Doesn’t)
    2 people · 2 points · first shared 2012 · discussion on HN
  11. 11
  12. 12
    7 Bits Are Not Enough for 2-Digit Accuracy
    1 people · 70 points · first shared 2015 · 27 comments on HN
  13. 13
    Visual C++ strtod(): Still Broken
    1 people · 38 points · first shared 2015 · 6 comments on HN
  14. 14
  15. 15
    Binary Division
    1 people · 9 points · first shared 2012 · discussion on HN

What HN people wrote when they linked it

userbinator · 2019-02-06
One of my favourite sites for explaining floating-point, especially the more subtle aspects, is https://www.exploringbinary.com/ . Here's a similar article from that site: https://www.exploringbinary.com/the-spacing-of-binary-floating-point-n…
jabot · 2017-12-01
Urgh. C semantics. Well, at least that will not happen if you actually use IEEE754 _and_ if a, b, and c all have the same floating point precision _and_ there is no weird promotion/precision change going on. Now that you mention, there was this fascinating denial-of-service vulnerability in PHP which is (kind of) related... https://news.ycombinator.com/item?id=2066352 http://www.exploringbinary.com/why-volatile-fixes-the-2-22507385850720… EDIT: To expand on this: The following code is valid, and may print "weird": double x = f(); double y = x; if(x != 0 && y == 0) { printf("weird\n"); } ... if x is stored in a 80bit floating point register, and y is stored in memory and therefore only has 64bit
mananaysiempre · 2025-12-19
Theoretically a good fuzzer could discover this value by itself, but I don’t believe anything like that exists that could run JS code and explore VM-level branches, at least not for JS code that’s even this complex. Otherwise, yes, PBT is less trivial than it seems, though I’m guessing a simple `strings jsc` coupled with general knowledge of special values of other types[1,2] could get you quite far. [1] https://www.exploringbinary.com/php-hangs-on-numeric-value-2-225073858… [2] https://www.exploringbinary.com/java-hangs-when-converting-2-225073858…
haberman · 2021-03-22
A surprising fact I just learned about float parsing is that it is absolutely trivial (and, I expect, very fast) if you are willing to tolerate a 1 ULP inaccuracy: https://www.exploringbinary.com/quick-and-dirty-decimal-to-floating-po… (Though 1/100M randomly tested conversions had a 14ULP inaccuracy, so I guess the inaccuracy is a bit unpredictable).
Someone · 2021-03-05
Probably https://www.exploringbinary.com/java-hangs-when-converting-2-225073858… “Java — both its runtime and compiler — go into an infinite loop when converting the decimal number 2.2250738585072012e-308 to double-precision binary floating-point. This number is supposed to convert to 0x1p-1022, which is DBL_MIN; instead, Java gets stuck, oscillating between 0x1p-1022 and 0x0.fffffffffffffp-1022, the largest subnormal double-precision floating-point number.”
SloopJon · 2020-10-30
I think Python was the first to bring this into my consciousness. See this enhancement request, which changed the float-to-string conversion from seventeen significant figures to shortest: https://bugs.python.org/issue1580 After they did that, I learned that Scheme specifies similar behavior. In fact, I think it was added to R4RS after the Steele and White paper. As the article says, this behavior spread across languages, so that it's weird to see something different now. If you want to nerd out on this, here are a few other posts that explore the topic: https://www.exploringbinary.com/the-shortest-decimal-string-that-round… https://www.exploringbinary.com/the-shortest-decimal-string-that-round… https://www.exploringbinary.com/java-doesnt-print-the-shortest-strings…
marmaduke · 2020-10-19
I think your provocative comment belies a challenging truth: federated trust. I can be a rational person and in my rationality delegate the conclusions on climate questions to those who are funded to spend their time, with my trust essentially delegating to the peer reviewed journals and journalists describing their work. We don’t however need science or such federated rationality to tell us what 2+2 is, rather why 1+3 in floating point is not 4, https://www.exploringbinary.com/floating-point-questions-are-endless-o…
77pt77 · 2020-05-26
> Another biggie is floating point. Converting binary floating point to decimal floating point and vice versa is VERY VERY VERY SLOW, difficult to get right Never forget the cluster bug in PHP because the developers decided they needed to reinvent the wheel[1]. [1] https://www.exploringbinary.com/php-hangs-on-numeric-value-2-225073858…
hyperman1 · 2020-05-26
Java had a variant of that bug too: https://www.exploringbinary.com/java-hangs-when-converting-2-225073858… It sits in a loop flip-flopping between 2 representations, each time deciding the other one is better. This turned into a DOS, as some web servers used floating point when decoding time zones from the http request header. So if your server has e.g. 20 http acceptor threads, someone could send 20 requests with an insane time zone, each sending 1 thread in an infinite loop.
pascal_cuoq · 2019-08-23
As the parent already said, the nice thing about hexadecimal floating-point is that the standard MANDATES that you get exactly the float/double you have uniquely described. The assertion “you can uniquely identify all floats by printing them with printf("%1.8e")” on the other hand relies on the compiler using round-to-nearest for conversions between binary and decimal, which the standard does not mandate and which, even when the compiler documents the choice, is sophisticated enough that the compiler/printf/strtod may get it wrong for difficult inputs: https://www.exploringbinary.com/tag/bug/
RandomOpinion · 2017-03-02
>Many people think floating point numbers are magically precise. Even worse, it kicks in earlier than one might naively think. People are often surprised to hear a value as simple as 0.1 has no matching floating point representation. (For those interested, http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floatin… has a nicely illustrated explanation.)
MrQuincle · 2016-10-30
This is a nice example of how much work goes into a good implementation: http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/
dingaling · 2015-09-27
Too late, we've already sent self-addressed envelopes out into the Cosmos. http://www.exploringbinary.com/binary-code-on-the-pioneer-10-spacecraf…
xchip · 2015-06-13
Wow lucky you your nephew is interested in learning. Go for pacman, but before make sure he plays a bit so he gets kind of addicted to it. Then to spark his curiosity ask him questions about how he thinks it works, something like this: http://www.exploringbinary.com/how-i-taught-third-graders-binary-numbe… Have fun! :)
wglb · 2015-01-17
Not to be confused with the number that hung java: http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585… Or the other number that hung PHP: http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585… Pre-auth DoS may result.
RickRegan · 2013-01-29
0.921875 is 921875/10^6 = 59/64, which is exactly representable in binary since 64 (2^6) is a power of two. So 1.921875 * 2^6 = 1 59/64 * 64 = 64 + 59 = 123. Or as acqq pointed out, the bit representations are the same: 1.921875 = 1.111011 (using my converter at http://www.exploringbinary.com/binary-converter/ ), which is 123 (1111011) shifted right 6 bits.
0x0 · 2013-01-27
Reminds me about that fairly recent strtod() infinite loop that caused DoS in several languages. http://www.exploringbinary.com/why-volatile-fixes-the-2-22507385850720…
kamkha · 2011-11-23
Here's a block of code that will cause most versions of the Java compiler to hang that doesn't use loops or templates: class compilehang { public static void main(String[] args) { double d = 2.2250738585072012e-308; System.out.println("Value: " + d); } } From http://www.exploringbinary.com/a-closer-look-at-the-java-2-22507385850… apparently the constant in the code above causes Java's double value correction loop to oscillate between two values, thus causing the compiler to hang.
corin_ · 2011-06-14
Maybe overly pedantic, but I don't like http://www.exploringbinary.com/wp-content/uploads/27.decimal.png For the tens you're counting lines of blocks, and for the ones you're counting blocks, so it doesn't match up. Maybe if the ones were lined horizontally so you're still counting vertical lines, they just happen to be 1 block tall instead of 10 blocks tall.

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close