automatic Inf+NaN*i conversion
Jaroslav Hajek
highegg at gmail.com
Fri Apr 25 06:49:56 CDT 2008
On Fri, Apr 25, 2008 at 11:21 AM, Rolf Fabian <Rolf.Fabian at gmx.de> wrote:
>
> I consider the automatic conversion of input 'Inf+NaN*i'
> to 'NaN-NaN*i' as a bug because this may lead to strange
> illogical consequences.
>
> octave-3.0.0.exe:1> x = [Inf+NaN*i,NaN+Inf*i]
> x =
> NaN - NaNi NaN + Infi
>
> ( If you consider the 1st element result 'NaN-NaNi' as intended,
> can you please explain the meaning of the appearing minus sign? )
>
The minus sign seems to be a bug. Actually, it appears that Octave can
deliberately use a NaN with sign bit set as the default NaN. The
problem can be tracked down to
liboctave/lo-ieee.cc, where the statement
octave_NaN = tmp_inf / tmp_inf;
can apparently return "negative" NaN - i.e. one with the signbit set.
Try this C program:
#include <math.h>
#include <stdio.h>
int main()
{
volatile double inf = HUGE_VAL;
volatile double nan = inf/inf;
printf ("%lf \n", inf);
printf ("%lf %d\n", nan, signbit (nan));
printf ("%lf %d\n", nan, signbit (-nan));
}
With my gcc, the output is:
inf
nan -2147483648
nan 0
the attached changeset seems to provide an acceptable quick-fix for
this (it works for me).
If this method does not work for some configurations (i.e. the sign
bit of NaN cannot be inverted, then we probably need to avoid using
lo_ieee_signbit in pr-output.cc).
The rest, as you have suspected, is intended behaviour, given by the
fact that `Inf' and `NaN' are functions.You can construct exceptional
complex numbers reliably using `complex'.
> octave-3.0.0.exe:2> isnan(x)
> ans =
> 1 1 # agree
>
> Checking x for finiteness :
> octave-3.0.0.exe:3> finite (x)
> ans =
> 0 0 # agree
>
> But the result of the following check contradicts
> above result because 1st element of x cannot be
> neither finite nor infinite !
I believe that's exactly true for NaN - it is neither finite nor
infinite. What support do you have for the opposite claim?
> octave-3.0.0.exe:4> isinf (x)
> ans =
> 0 1 # disagree with respect to 1st element
>
> R:
>
>
>
> -----
> Rolf Fabian
> <r dot fabian at jacobs-university dot de>
>
> --
> View this message in context: http://www.nabble.com/automatic-Inf%2BNaN*i-conversion-tp16893696p16893696.html
> Sent from the Octave - Bugs mailing list archive at Nabble.com.
>
> _______________________________________________
> Bug-octave mailing list
> Bug-octave at octave.org
> https://www.cae.wisc.edu/mailman/listinfo/bug-octave
>
regards,
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nanbug.diff
Type: text/x-patch
Size: 1053 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080425/2e4140bd/attachment.bin
More information about the Bug-octave
mailing list