Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20790 > unrolled thread
| Started by | Jaroslav Dobrek <jaroslav.dobrek@gmail.com> |
|---|---|
| First post | 2012-02-24 00:41 -0800 |
| Last post | 2012-02-24 02:16 -0800 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
subtraction of floating point numbers Jaroslav Dobrek <jaroslav.dobrek@gmail.com> - 2012-02-24 00:41 -0800
Re: subtraction of floating point numbers Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-02-24 09:49 +0100
Re: subtraction of floating point numbers Chris Rebert <clp2@rebertia.com> - 2012-02-24 02:16 -0800
| From | Jaroslav Dobrek <jaroslav.dobrek@gmail.com> |
|---|---|
| Date | 2012-02-24 00:41 -0800 |
| Subject | subtraction of floating point numbers |
| Message-ID | <a4dbc794-db02-4cc4-a22a-cf64c91bbb50@v2g2000vbx.googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Alain Ketterlin <alain@dpt-info.u-strasbg.fr> |
|---|---|
| Date | 2012-02-24 09:49 +0100 |
| Message-ID | <87pqd462gk.fsf@dpt-info.u-strasbg.fr> |
| In reply to | #20790 |
Jaroslav Dobrek <jaroslav.dobrek@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.
[toc] | [prev] | [next] | [standalone]
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2012-02-24 02:16 -0800 |
| Message-ID | <mailman.119.1330078592.3037.python-list@python.org> |
| In reply to | #20790 |
On Fri, Feb 24, 2012 at 12:41 AM, Jaroslav Dobrek <jaroslav.dobrek@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web