nan or -nan?
Iain Buclaw
ibuclaw at ubuntu.com
Thu Nov 17 15:37:31 PST 2011
On 16 November 2011 04:35, Ali Çehreli <acehreli at yahoo.com> wrote:
> Some floating point operations produce .nan:
>
> import std.stdio;
>
> void main()
> {
> double zero = 0;
> double infinity = double.infinity;
>
> writeln("any expression with nan: ", double.nan + 1);
> writeln(" zero / zero : ", zero / zero);
> writeln(" zero x infinity : ", zero * infinity);
> writeln("infinity / infinity : ", infinity / infinity);
> writeln("infinity - infinity : ", infinity - infinity);
> }
>
> Last time I checked, I think the program above would produce nan for all of
> those operations. Now some are -nan when compiled with 64-bit dmd 2.056 on
> Linux:
>
> any expression with nan: nan
> zero / zero : -nan
> zero x infinity : -nan
> infinity / infinity : -nan
> infinity - infinity : -nan
>
> Is that expected? Does it matter?
>
> Ali
>
This behaviour may be due to the libraries rather than the compiler.
But whether the bit that controls signed-ness is on or off, doesn't
stop the value being NaN. So I would not give much concern to the
result.
--
Iain Buclaw
*(p < e ? p++ : p) = (c & 0x0f) + '0';
More information about the Digitalmars-d
mailing list