what is this?

  • Thread starter Herbert Fritsch
  • Start date
H

Herbert Fritsch

Hi,
I'm a real beginner with python and I don't really know if I will get it.
But here is one of my first exercises:

Python 2.3+ (#1, Sep 23 2003, 23:07:16)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.0.80000000000000004

There must be something wrong. I' running the new Suse 9.0.

Herbert
 
J

Jay Dorsey

Herbert said:
0.80000000000000004

There must be something wrong. I' running the new Suse 9.0.

Not really. Think of the order of operations in mathematics.
Multiplication and division are ranked higher than addition. Using
parentheses for grouping is higher (before) mulitplication and division.

First example:

4 / 2 + 3 yields 2 + 3 yields 5

Second:

4 / (2.0 + 3)

Python coerces the 3 into a floating point number, so lets write all
these as floating points:

4.0 / (2.0 + 3.0)

Order of operations says do the parentheses first:

4.0 / 5.0 yields 0.8000000000000004

Theres a listing of Pythons order of operations somewhere in the
documentation on python.org (couldn't find it with a quick search).

:)
 
H

Hari Pulapaka

Hi,

Most newbies to python, have probably experienced this one time or
another. And posted it to the newsgroups, where the Python gurus, will
say, No foo thats how floating points are represented, read the tutorial
and understand floating point representation, etc...

But call it whatever, 3.4 != 3.3999999999999999 and I feel that
somewhere some change should be made so that the representation is better.

I saw some discussion earlier where, someone provided a function for
repr so that the presentation of floating is better and it looked like
(to me) that it had a solution for this problem.

- Hari

Herbert said:
Hi,
I'm a real beginner with python and I don't really know if I will get it.
But here is one of my first exercises:

Python 2.3+ (#1, Sep 23 2003, 23:07:16)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

0.80000000000000004

There must be something wrong. I' running the new Suse 9.0.

Herbert
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top