Mike Miller a écrit :

> On Tue, 14 Jun 2005, David Bateman wrote:

>

>> Søren Hauberg a écrit :

>>

>>> a = zeros(3); a(5) = NaN;

>>> octave:25> save -float-binary test.data a

>>>

>>> which gives me the following warning:

>>>

>>> warning: save: some values too large to save as floats --

>>> warning: save: saving as doubles instead

>>>

>>> Btw. I'm using 2.1.71 on linux

>>

>>

>> That's pretty stupid behaviour... Perhaps the test for whether data

>> can be saved as float needs to be updated to allow that NaN can be

>> saved as float.....

>

>

>

> How is NaN encoded? The "too large to save as floats" seems to imply

> that NaN is encoded as a large value. Is that the case?

>

> Mike

No it implies that the > and < operators with NaN on the left-hand side

always return true... Consider the attached patch (John do I commit it?)

D.

2005-06-14 David Bateman <

[hidden email]>

* dMatrix.cc (too_large_for_float): Special case NaN and NA values

* CMatrix.cc (too_large_for_float): Ditto

*** liboctave/CMatrix.cc~ 2005-04-28 23:42:46.000000000 +0200

--- liboctave/CMatrix.cc 2005-06-14 16:51:07.532501906 +0200

***************

*** 2607,2616 ****

double r_val = std::real (val);

double i_val = std::imag (val);

! if (r_val > FLT_MAX

! || i_val > FLT_MAX

! || r_val < FLT_MIN

! || i_val < FLT_MIN)

return true;

}

--- 2607,2616 ----

double r_val = std::real (val);

double i_val = std::imag (val);

! if (((! octave_is_NaN_or_NA (r_val)) &&

! (r_val > FLT_MAX || r_val < FLT_MIN)) ||

! ((! octave_is_NaN_or_NA (i_val)) &&

! (i_val > FLT_MAX || i_val < FLT_MIN)))

return true;

}

*** liboctave/dMatrix.cc~ 2005-04-26 21:28:16.000000000 +0200

--- liboctave/dMatrix.cc 2005-06-14 16:47:20.121487592 +0200

***************

*** 2114,2120 ****

{

double val = elem (i);

! if (val > FLT_MAX || val < FLT_MIN)

return true;

}

--- 2114,2120 ----

{

double val = elem (i);

! if ((! octave_is_NaN_or_NA (val)) && (val > FLT_MAX || val < FLT_MIN))

return true;

}