[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: floating point precision question

**From**: |
Martin Helm |

**Subject**: |
Re: floating point precision question |

**Date**: |
Tue, 18 Jan 2011 13:28:45 +0100 |

**User-agent**: |
KMail/1.13.5 (Linux/2.6.34.7-0.7-desktop; KDE/4.5.5; x86_64; ; ) |

Am Dienstag, 18. Januar 2011, 13:04:39 schrieb Piotr Isajew:
>* Hi,*
>* *
>* I've been trying to use Octave (3.2.4) for some very simple*
>* computations, and noticed a strange behaviour when*
>* incrementing/comparing floating point numbers. In short:*
>* *
>* *
>* octave:150> 0.15 == (0.10 + 0.05)*
>* ans = 0*
>* *
>* why?*
>* *
>* An even better test is:*
>* *
>* octave:1> A=0.15*
>* A = 0.15000*
>* octave:2> B=(0.10+0.05)*
>* B = 0.15000*
>* octave:3> A==B*
>* ans = 0*
>* octave:4> save /tmp/test A B*
>* octave:5> A==B*
>* ans = 0*
>* octave:6> load /tmp/test A B*
>* octave:7> A==B*
>* ans = 1*
>* *
>* Is there any setting I could use to obtain better precision here?*
This is not a question of precision but a question of representation. Numbers
like 0.1 cannot be represented exactly as binary fractions independent on how
many bits per number you use. Google for IEEE 754 or just have a look at this
elementary article which explains it much better
http://en.wikipedia.org/wiki/Floating_point