[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 0.3*3 == 0.9?
From: |
Marc Weber |
Subject: |
Re: 0.3*3 == 0.9? |
Date: |
Wed, 25 Aug 2010 16:21:50 +0200 |
User-agent: |
Sup/git |
Hi Michael,
take *any* book and learn about internal number representation.
Numbers are represented in dual format rather than decimal.
This means that 0.9 (which looks nice in decimal) can be something like
.111111 (repeat infinitely) in dual representation (something like 1/3
in decimal which is 0.33333... )
Thus 0.9 != 0.9.
Conclusion: Never ever use strict equality for comparison. Always use
abs(number1 - number2) < 0.000001 or something like that.
Probably octave has functions for that - don't know it well enough.
Digg around in existing code - maybe you find how its done there.
I'm not an Octave expert.
Marc Weber
- 0.3*3 == 0.9?, Michael Creel, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Michael Creel, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Jaroslav Hajek, 2010/08/25
- Re: 0.3*3 == 0.9?, Michael Creel, 2010/08/25
- Re: 0.3*3 == 0.9?, José Luis García Pallero, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Jaroslav Hajek, 2010/08/26
Re: 0.3*3 == 0.9?,
Marc Weber <=
Re: 0.3*3 == 0.9?, CdeMills, 2010/08/26