Top
Best
New

Posted by ColinWright 10/26/2025

987654321 / 123456789(www.johndcook.com)
636 points | 107 commentspage 3
_def 6 days ago|
> The exact ratio is not 14, but it’s as close to 14 as a standard floating point number can be.

How do you get around limitations like that in science?

sltkr 6 days ago||
For rational numbers, Python has a Fraction class in the standard library that performs exact integer arithmetic:

    >>> from fractions import Fraction
    >>> f = Fraction(0xFEDCBA987654321, 0x123456789ABCDEF)
    >>> f%1
    Fraction(1, 5465701947765793)
    >>> f - f%1
    Fraction(14, 1)
That shows that 0xFEDCBA987654321 / 0x123456789ABCDEF = 14 + 1/5465701947765793 exactly.

    >>> math.log(5465701947765793, 2)
    52.279328213174445
Shows that the denominator requires 52 bits which is slightly more than the number of mantissa bits in a 64-bit floating point number, so the result gets rounded to 14.0 due to limited precision.
gus_massa 6 days ago|||
You can use Mathematica or Sage that can use any number of digits https://www.wolframalpha.com/input?i=FEDCBA987654321_16+%2F+...

You can use special libraries for floating point that uses more mantisa.

In most sciences, numbers are never integers anyway, so you have errors intervals in the numerator and denumerator and you get an error interval for the result.

necovek 6 days ago||
You can do symbolic calculations carrying precisely defined numbers (eg. PI, 3/7...), you can use tools which allow arbitrary precision (it's only slower by several orders of magnitude so not too bad if you don't need millions of calculations: this includes Python if you use Decimal objects), or you can use error calculus to decide if the final error is acceptable.
nomilk 6 days ago||
TIL 0x denotes hexadecimal E.g.

> 0xFEDCBA987654321 / 0x123456789ABCDEF

(somehow I'd seen the denotation for years yet never actually known what it was).

extraduder_ire 5 days ago|
Numbers with a leading 0 are octal (base 8) in many programming languages too.
MontyCarloHall 6 days ago||
In a similar vein, e^pi - pi = 19.9990999792, as referenced in this XKCD: https://xkcd.com/217/
zkmon 6 days ago||
Also, (-1)^(-i) - pi = 19.999... ;)
madcaptenor 6 days ago||
Not really in a similar vein, because there's actually a good reason for this to be very close to an integer whereas there is no such reason for e^pi - pi.
tempfile 6 days ago|||
No known reason :-)
scriptweaver 5 days ago||
Math can be so fun when you find patterns like this, it’s like hidden magic in numbers.
uticus 6 days ago||
this reminds me of the online encyclopedia of integer sequences (https://oeis.org/). anything similar for things like 987654321 / 123456789 ?
uticus 6 days ago|
...followup after looking through comments on OP, indeed someone else already had the idea to tie in OEIS sequences in the comment at https://www.johndcook.com/blog/2025/10/26/987654321/#comment...

but i still wonder if there is something like OEIS for observations / analysis like this

madcaptenor 6 days ago||
That was me. The best I know is to find a related sequence and look it up in the OEIS.
CoderLim110 5 days ago||
The beauty of mathematics, imperfection is also a kind of beauty.
jojobas 6 days ago||
12345679 (oh no, we forgot the 8!) - let's multiply by 8 = 98765432.
lutusp 6 days ago||
> I recently saw someone post [1] that 987654321/123456789 is very nearly 8, specifically 8.0000000729.

Okay. Try this (in a Python terminal session):

>>> 111111111 ** 2

12345678987654321

(typo corrected)

notorandit 6 days ago||
May I Say 355/113 ?
More comments...