Reducing types

B

bearophileHUGS

For me Python is useful to write code that gives *correct* results,
allowing me to write it in a short & simple way, with quick debugging
cycles (and for other purposes, like to write dynamic code, to use it
as glue language to use libraries, to create quick GUIs, as scripting
for data munging, etc). When I need more speed I use the D language,
or Psyco, or C, etc.

Python 2.5 has string, unicode, long, int, float, and Decimal types.
Python 3.0 reduces them to string (+ the byte type) int, float, and
Decimal. So why not adopt the Decimal (IEEE 854) as the standard
"float" for Python (if speed is a concern, than a mfloat type may be
introduced, it's a "machine float", it's essentially the "float" of
Python 2.5, operations between a float and a mfloat give a mfloat)? It
can reduce some FP bugs, and avoid those 5.89 + 3.99 =
9.879999999999999 bugs that puzzle newbies, that are okay in a very
fast low-level language like C++, but probably unfit for a high-level
one :)

Bye,
bearophile
 
P

Paul McGuire

So why not adopt the Decimal (IEEE 854) as the standard
"float" for Python (if speed is a concern, than a mfloat type may be
introduced, it's a "machine float", it's essentially the "float" of
Python 2.5, operations between a float and a mfloat give a mfloat)? It
can reduce some FP bugs, and avoid those 5.89 + 3.99 =
9.879999999999999 bugs that puzzle newbies, that are okay in a very
fast low-level language like C++, but probably unfit for a high-level
one :)

Bye,
bearophile

Sounds like you've been reading about Cobra...

-- Paul
 
B

bearophileHUGS

Paul McGuire:
Sounds like you've been reading about Cobra...

I have heard about that language (for dotnet?) but my idea doesn't
come from Cobra...

Bye,
bearophile
 
D

Dan Bishop

For me Python is useful to write code that gives *correct* results,
allowing me to write it in a short & simple way, with quick debugging
cycles (and for other purposes, like to write dynamic code, to use it
as glue language to use libraries, to create quick GUIs, as scripting
for data munging, etc). When I need more speed I use the D language,
or Psyco, or C, etc.

Python 2.5 has string, unicode, long, int, float, and Decimal types.
Python 3.0 reduces them to string (+ the byte type) int, float, and
Decimal. So why not adopt the Decimal (IEEE 854) as the standard
"float" for Python (if speed is a concern, than a mfloat type may be
introduced, it's a "machine float", it's essentially the "float" of
Python 2.5, operations between a float and a mfloat give a mfloat)? It
can reduce some FP bugs, and avoid those 5.89 + 3.99 =
9.879999999999999 bugs that puzzle newbies, that are okay in a very
fast low-level language like C++, but probably unfit for a high-level
one :)

(1) Because, although speed may not be the primary focus of Python,
it's still relevant. And float has a HUGE speed advantage over
Decimal.

(2) Because decimal arithmetic isn't a panacea for floating-point
errors. I have a decimal calculator at hand, and while it gives the
correct result for 5.89 + 3.99, it gives slightly incorrect results
for 1/3*3 and sqrt(3)**2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top