Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
subtraction of floating point numbers
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jaroslav Dobrek  
View profile  
 More options Feb 24, 3:41 am
Newsgroups: comp.lang.python
From: Jaroslav Dobrek <jaroslav.dob...@gmail.com>
Date: Fri, 24 Feb 2012 00:41:21 -0800 (PST)
Local: Fri, Feb 24 2012 3:41 am
Subject: subtraction of floating point numbers
Hello,

when I have Python subtract floating point numbers it yields weird
results. Example:

4822.40 - 4785.52 = 36.8799999999992

Why doesn't Python simply yield the correct result? It doesn't have a
problem with this:

482240 - 478552 = 3688

Can I tell Python in some way to do this differently?

Jaroslav


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alain Ketterlin  
View profile  
 More options Feb 24, 3:49 am
Newsgroups: comp.lang.python
From: Alain Ketterlin <al...@dpt-info.u-strasbg.fr>
Date: Fri, 24 Feb 2012 09:49:15 +0100
Local: Fri, Feb 24 2012 3:49 am
Subject: Re: subtraction of floating point numbers

Jaroslav Dobrek <jaroslav.dob...@gmail.com> writes:
> when I have Python subtract floating point numbers it yields weird
> results. Example:

> 4822.40 - 4785.52 = 36.8799999999992

We've had this discussion here one or two days ago...

The usual answer is: please read "What Every Computer Scientist Should
Know About Floating Point Arithmetic", at:

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768

and check the answers posted these last days. In brief: you're working
with floating point numbers, not reals (i.e., real "reals"). That's
life. Deal with it, or move to specialized packages, like decimal.

-- Alain.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Rebert  
View profile  
 More options Feb 24, 5:16 am
Newsgroups: comp.lang.python
From: Chris Rebert <c...@rebertia.com>
Date: Fri, 24 Feb 2012 02:16:29 -0800
Local: Fri, Feb 24 2012 5:16 am
Subject: Re: subtraction of floating point numbers
On Fri, Feb 24, 2012 at 12:41 AM, Jaroslav Dobrek

<jaroslav.dob...@gmail.com> wrote:
> Hello,

> when I have Python subtract floating point numbers it yields weird
> results. Example:

> 4822.40 - 4785.52 = 36.8799999999992

> Why doesn't Python simply yield the correct result? It doesn't have a
> problem with this:

> 482240 - 478552 = 3688

> Can I tell Python in some way to do this differently?

Refer to this thread from 2 days ago:
http://mail.python.org/pipermail/python-list/2012-February/1288344.html

Regards,
Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »