octave-bug-tracker
[Top][All Lists]

## [Octave-bug-tracker] [bug #35024] magnitude abs(a) != sqrt(a_r^2 + a_i^2

 From: Alois Schlögl Subject: [Octave-bug-tracker] [bug #35024] magnitude abs(a) != sqrt(a_r^2 + a_i^2) Date: Fri, 09 Dec 2011 08:02:09 +0000 User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111107 Ubuntu/10.04 (lucid) Firefox/3.6.24

```Follow-up Comment #1, bug #35024 (project octave):

That's the world of floating point numbers. To make the long story short, it's
not a bug, its a feature.

Octave is (mostly) using the floating point representation according to IEEE
754/874, which is supported in hardware by many cpu's, and is therefore quite
fast (much much faster than arbitrary precision arithmetic.).

If you want to know more about the issue, see [1,2]. For all practical
purposes, you can solve the problem not by comparing against zero
(abs(a) - sqrt(13))==0
but by testing whether the difference is within some multiple of the machine
precision e.g.

abs(abs(a) - sqrt(13)) < 10 * eps

Alois

[1] https://secure.wikimedia.org/wikipedia/en/wiki/IEEE_754-2008

[2] What Every Computer Scientist Should Know About Floating-Point Arithmetic,
by David Goldberg, published in the March, 1991 issue of Computing Surveys.

_______________________________________________________

<http://savannah.gnu.org/bugs/?35024>

_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/

```