python rounding problem.

Thomas Bartkus thomasbartkus at
Mon May 8 22:57:36 CEST 2006

"Grant Edwards" <grante at> wrote in message
news:125v9g8q00o1d52 at
> On 2006-05-08, Thomas Bartkus <thomasbartkus at> wrote:
> >> does python support true rations, which means that 1/3 is a
> >> true one-third and not 0.333333333 rounded off at some
> >> arbitrary precision?
> >
> > At risk of being boring  ;-)
> >
> > - Python supports both rational and irrational numbers as
> >   floating point numbers the way any language on any digital
> >   computer does - imprecisely.
> >
> > A "true" (1/3) can only be expressed as a fraction.
> At the risk of being both boring and overly pedantic, that's
> not true.  In base 3, the value in question is precisely
> representable in floating point: 0.1
> > As soon as you express it as a floating point - you are in a
> > bit of trouble because that's impossible.
> It's not possible in base 2 or base 10.  It's perfectly
> possible in base 9 (used by the Nenets of Northern Russia) base
> 12 (popular on planets where everybody has twelve toes) or base
> 60 (used by th Sumerians).  [I don't know if any of those
> peoples used floating point in those bases -- I'm just pointing
> out that your prejudice towards base 10 notation is showing.]
> > You can not express (1/3) as a floating point in Python any
> > more than you can do it with pencil and paper.
> That's true assuming base 2 in Python and base 10 on paper. The
> base used by Python is pretty much etched in stone (silicon, to
> be precise).  There used to be articles about people working on
> base-3 logic gates, but base-3 logic never made it out of the
> lab. However, you can pick any base you want when using paper
> and pencil.
> > You can be precise and write "1/3" or you can surrender to
> > arithmetic convenience and settle for the imprecise by writing
> > "0.333333333", chopping it off at some arbitrary precision.
> Or you can write  0.1
>                      3
> :)

But if I need to store the value 1/10 (decimal!), what kind of a precision
pickle will I then find myself while working in base 3 ?  How much better
for precision if we just learn our fractions and stick to storing integer
numerators alongside integer denominators in big 128 bit double registers ?

Even the Nenets might become more computationally precise by such means ;-)
And how does a human culture come to decide on base 9 arithmetic anyway?
Even base 60 makes more sense if you like it when a lot of divisions come
out nice and even.

Do the Nenets amputate the left pinky as a rite of adulthood ;-)
Thomas Bartkus

More information about the Python-list mailing list