* NaN in C/C++ on OSF1
@ 1995-12-01 5:00 Jan Christian Kerlefsen
1995-12-07 5:00 ` Steven Hobbs
0 siblings, 1 reply; 3+ messages in thread
From: Jan Christian Kerlefsen @ 1995-12-01 5:00 UTC (permalink / raw)
Hi!
I'm porting an application developed on SunOS 4.1.3, to a Dec Alpha with OSF1
v3.2.
The application is implemented in C++ and compiled with gcc 2.6.3.
It is essencial for the application that double and float variables can be NaN
(not a number).
On Sun i use the function 'double quiet_nan()' in 'libm', and on AIX 3.2 I use
sqrt(-1.0) to get the NaN value.
The 'libm' on OSF1 has the function 'int isnanf(float)' that gives the correct
response when I use FLT_QNAN defined in float.h.
i.e.
float a = FLT_QNAN;
if (isnanf(a))
cerr << a;
works fine, and prints 'NaN' to std.out.
But:
float a = FLT_QNAN;
float b = 1.0;
float c;
c=a+b;
crashes with a floating exception. I had expected c to be assigned NaN.
sqrt(-1.0) returns 0 (!), and isnan(sqrt(-1.0)) returns 0 on the OSF1.
On sun:
#include <math.h>
#include <iostream.h>
main() {
float a = quiet_nan();
float c,b=1.0;
c=a+b;
cerr << c;
}
works as expected and prints 'NaN' to std.out.
I need a 'quiet nan' on OSF1 that works the same way as it does on Sun.
By the way, when linking on the OSF1, I get the following warning:
/usr/bin/ld:
Warning: Linking some objects which contain exception information sections
and some which do not. This may cause fatal runtime exception handling
problems (last obj encountered without exceptions was
(some file..)
I've been told that this warning can be ignored. Is this true, also in the case
with the 'NaN' problems?
Thanks in advance for help!
Jan Christian Kerlefsen email: Christian.Kerlefsen@nr.no
Research Scientist Phone: +47 22 85 25 00
Norwegian Computing Centre Fax: +47 22 69 76 60
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: NaN in C/C++ on OSF1
1995-12-01 5:00 NaN in C/C++ on OSF1 Jan Christian Kerlefsen
@ 1995-12-07 5:00 ` Steven Hobbs
1995-12-08 5:00 ` Tanmoy Bhattacharya
0 siblings, 1 reply; 3+ messages in thread
From: Steven Hobbs @ 1995-12-07 5:00 UTC (permalink / raw)
In article <49mnlh$5a3@ratatosk.uio.no>, janchr@holt.nr.no
(Jan Christian Kerlefsen) writes:
>
>Hi!
>I'm porting an application developed on SunOS 4.1.3, to a Dec Alpha with OSF1
>v3.2.
>The application is implemented in C++ and compiled with gcc 2.6.3.
>It is essencial for the application that double and float variables can be NaN
>(not a number).
The Alpha architecture gives the programmer a choice on whether to generate NaNs,
infinities and denormals or to signal an error whan floating point exceptions
occur. Code that produces signals on exceptions is faster than code that
handles the non-finite IEEE values. By default Digital Alpha compilers generate
code that signals but you can get portable IEEE floating point behavior by using
the -ieee_with_no_inexact switch with the cc command. The current Digital cxx
command does not include this switch but the next Digital C++ release (currently
in field test) will. I do not know the details of IEEE support in the Alpha
version of gcc. You should check the appropriate man page for this information.
Therefore, if you use cc with -ieee_with_no_inexact then sqrt(-1.0) will return
a quietNaN and arithmetic on quietNaNs will *not* generate a signal (unless you
enable signaling--see the ieee(3) man page). For historical reasons, sqrt(-1.0)
produces 0.0 when -ieee_with_no_inexact is not enabled.
[I usually use 0.0/0.0 to produce a NaN, rather than sqrt(-1.0)]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: NaN in C/C++ on OSF1
1995-12-07 5:00 ` Steven Hobbs
@ 1995-12-08 5:00 ` Tanmoy Bhattacharya
0 siblings, 0 replies; 3+ messages in thread
From: Tanmoy Bhattacharya @ 1995-12-08 5:00 UTC (permalink / raw)
In article <4a7lji$3j5@nntpd.lkg.dec.com>, hobbs@steven.zko.dec.com (Steven
Hobbs) writes:
<snip>
|> Therefore, if you use cc with -ieee_with_no_inexact then sqrt(-1.0) will
return
|> a quietNaN and arithmetic on quietNaNs will *not* generate a signal
(unless you
|> enable signaling--see the ieee(3) man page). For historical reasons,
sqrt(-1.0)
|> produces 0.0 when -ieee_with_no_inexact is not enabled.
According to ANSI C, unless you do some implementation defined magic (like
`enabling signals' etc.), sqrt(-1.0) must _not_ produce an exception. It can
return any value defined by the implementation.
Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1995-12-08 5:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-12-01 5:00 NaN in C/C++ on OSF1 Jan Christian Kerlefsen
1995-12-07 5:00 ` Steven Hobbs
1995-12-08 5:00 ` Tanmoy Bhattacharya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox