python rounding problem.
Thomas Bartkus
thomasbartkus at comcast.net
Tue May 9 21:08:53 CEST 2006
"Grant Edwards" <grante at visi.com> wrote in message
news:125vedc9n2q3m55 at corp.supernews.com...
> On 2006-05-08, Thomas Bartkus <thomasbartkus at comcast.net> wrote:
>
> >> Or you can write 0.1
> >> 3
> >>
> >> :)
> >
> > Ahhh!
> >
> > 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?
>
> Then we're right back where we started. No matter what base
> you choose, any fixed length floating-point representation can
> only represent 0% of all rational numbers.
>
> So, clearly what we need are floating point objects with
> configurable bases -- bases that automatically adjust to
> maintain exact representation of calculation results. Which
> probably exactly the same as just storing rational numbers as
> numerator,denominator tuples as you suggest.
>
> > 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 ?
I completely overlooked the infinite (presumably!) length integer handling
in Python. You can do integer arithmetic on integers of large and arbitrary
lengths and if ultimate precision were indeed so important (and I can't
imagine why!) then working with numerators and denominators stored as tuples
is quite practical.
Anyone old enough to remember Forth might remember the arguments about how
unnecessary floating point is. True enough! Floating point is merely a
convenience for which we sacrifice some (insignificant!) arithmetic
precision to enjoy.
> > 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?
>
> I've no clue, whatsoever. I just stumbled across that factoid
> when I used Wikipedia to look up which civilizations used
> base-60. For some reason I can never remember whether it was
> one of the mesoamerican ones or one of the mesopotamian ones.
I suspect a hoax or an urban legend here. A brief and casual googling
brings up the Nenets but no mention of base 9 arithmetic which I would find
rather astonishing.
Look up the Tasaday tribe together with the word "hoax". A great joke on
academic anthropologists really.
On the other hand, the name "Nenet" is full of "N"s and so evocative of the
number nine ;-)
> > Even base 60 makes more sense if you like it when a lot of
> > divisions come out nice and even.
>
> Did they actually have 60 unique number symbols and use
> place-weighting in a manner similar to the arabic/indian system
> we use?
I don't know.
I do know that we have 360 degrees in a circle for the simple reason that
this is evenly divisible by so damned many integers. A significant and
logical convenience if you have to do all your calculations on a wooden
board using the chunk of charcoal you hold in your fist.
Thomas Bartkus
> > Do the Nenets amputate the left pinky as a rite of adulthood
> > ;-)
>
> Nah, winters up there are so friggin' cold that nobody ever has
> more than nine digits by the time they reach adulthood.
>
> --
> Grant Edwards grante Yow! Hello. Just walk
> at along and try NOT to
think
> visi.com about your INTESTINES
being
> almost FORTY YARDS
LONG!!
More information about the Python-list
mailing list