RE: [Python-Dev] Re: Re: Decimal type question [Prothon]

the only reason programmers write loops as integers is because accumulating floats "doesn't work". With Decimal, that is no longer the case.
That is completely untrue. Binary floating point does just as good a job of handling integers as decimal floating point does. For instance: >>> accumulator = 0.0 >>> for i in range(25000): ... accumulator += 1.0 ... >>> print accumulator 25000.0 Notice, perfect accuracy. Yet people don't tend to use floating point for loops... why not? I'd argue there are at LEAST two other good reasons. Performance (floating point arithmatic is fast, but the equivalent integer arithmatic is normally faster), and clarity of intent (using an int type makes it clear that you intend only to use integers. But lots of languages make other choices. The number of languages that have a single numeric type is pretty large... perl comes to mind, but I bet I could list 10 others without too much trouble. -- Michael Chermside

For instance:
>>> accumulator = 0.0 >>> for i in range(25000): ... accumulator += 1.0 ... >>> print accumulator 25000.0
Notice, perfect accuracy. Yet people don't tend to use floating point for loops... why not?
Because the generalization to using fractions doesn't work. Try the same with adding 0.1, 25000 times. Better not be tempted. --Guido van Rossum (home page: http://www.python.org/~guido/)

On Wed, Aug 11, 2004 at 01:53:31PM -0700, Michael Chermside wrote:
But lots of languages make other choices. The number of languages that have a single numeric type is pretty large... perl comes to mind, but I bet I could list 10 others without too much trouble.
perl doesn't have a single numeric type. Depending on how deep you look into the issue, it has none (only a scalar type), or several (scalars that are assigned integers are integers until they are promoted to float when used floatishly). -- John Lenton (john@grulic.org.ar) -- Random fortune: What's so funny?
participants (3)
-
Guido van Rossum
-
John Lenton
-
Michael Chermside