FAQ: Difference between revisions

1,537 bytes added ,  20 September 2012
Line 521: Line 521:


If your problem truly persists with the latest version, as indicated [http://www.gnu.org/software/octave/download.html here], then by all means report a bug or ask for help, but don't be surprised if volunteers are less inclined to help you with a problem that only exists in an older version of Octave.
If your problem truly persists with the latest version, as indicated [http://www.gnu.org/software/octave/download.html here], then by all means report a bug or ask for help, but don't be surprised if volunteers are less inclined to help you with a problem that only exists in an older version of Octave.
== Why is this floating point computation wrong? ==
Floating point arithmetic is an approximation '''in binary''' to arithmetic on real or complex numbers. Just like you cannot represent 1/3 exactly in decimal arithmetic (0.333333 is only a rough approximation to 1/3), you cannot represent some decimals like 0.1 exactly in base 2. In binary, the representation to one tenth is <math>0.\overline{00011}</math> where the bar indicates that it repeats infinitely (like how 1/3 = 0.\overline{3} in decimal). Because this infinite repetition cannot be represented exactly, rounding errors occur for values that appear to be exact in decimal but are in fact approximations in binary, such as for example how 0.3 - 0.2 - 0.1 is not equal to zero.
This isn't an Octave bug. It happens with any program that uses [http://en.wikipedia.org/wiki/IEEE_754 IEEE 754 floating point arithmetic]. The reason why Octave and other programs use IEEE 754 floats is that they are '''fast''', because they are implemented in hardware, in your computer's processor. If you need arbitrary-precision arithmetic, which is inevitably slower as it has to be implemented in software instead of hardware, you may use the vpa function from the symbolic package.
To learn more about floating point arithmetic, consult [http://en.wikipedia.org/wiki/Floating_point_arithmetic its Wikipedia article] or the classical reference [http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html What Every Computer Scientist Should Know About Floating Point Arithmetic].


=Porting programs from Matlab to Octave=
=Porting programs from Matlab to Octave=