[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Reducing types

Bearophile

2/10/2008 7:20:00 PM

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
3 Answers

Paul McGuire

2/10/2008 7:48:00 PM

0

On Feb 10, 1:19 pm, bearophileH...@lycos.com wrote:
> 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

Bearophile

2/10/2008 8:15:00 PM

0

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

Dan Bishop

2/11/2008 1:18:00 AM

0

On Feb 10, 1:19 pm, bearophileH...@lycos.com wrote:
> 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.