Top
Best
New

Posted by ColinWright 10/26/2025

987654321 / 123456789(www.johndcook.com)
637 points | 107 commentspage 3
_def 10/30/2025|
> 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 10/30/2025||
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 10/30/2025|||
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 10/30/2025||
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 10/30/2025||
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 10/31/2025|
Numbers with a leading 0 are octal (base 8) in many programming languages too.
MontyCarloHall 10/30/2025||
In a similar vein, e^pi - pi = 19.9990999792, as referenced in this XKCD: https://xkcd.com/217/
zkmon 10/30/2025||
Also, (-1)^(-i) - pi = 19.999... ;)
madcaptenor 10/30/2025||
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 10/30/2025|||
No known reason :-)
scriptweaver 10/31/2025||
Math can be so fun when you find patterns like this, it’s like hidden magic in numbers.
uticus 10/30/2025||
this reminds me of the online encyclopedia of integer sequences (https://oeis.org/). anything similar for things like 987654321 / 123456789 ?
uticus 10/30/2025|
...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 10/30/2025||
That was me. The best I know is to find a related sequence and look it up in the OEIS.
jojobas 10/30/2025||
12345679 (oh no, we forgot the 8!) - let's multiply by 8 = 98765432.
CoderLim110 10/31/2025||
The beauty of mathematics, imperfection is also a kind of beauty.
lutusp 10/30/2025||
> 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 10/30/2025||
May I Say 355/113 ?
More comments...