IEEE float pont support in FreeBSD and GCC

IEEE float pont support in FreeBSD and GCC

Post by Thoma » Mon, 04 Dec 2000 15:05:17



Hi,
I have found out that NaN is not supported by gcc under FreeBSD. But FreeBSD
is supposed to support IEEE float point standard 754, right?

thanks,
Thomas

 
 
 

IEEE float pont support in FreeBSD and GCC

Post by Mikhail Kru » Mon, 04 Dec 2000 16:11:49


I wonder how exactly you found out that NaN is not supported. So far I've been
finding out that it is supported quite well (i.e. it's there)

> Hi,
> I have found out that NaN is not supported by gcc under FreeBSD. But FreeBSD
> is supposed to support IEEE float point standard 754, right?

> thanks,
> Thomas


 
 
 

IEEE float pont support in FreeBSD and GCC

Post by naisbod » Mon, 04 Dec 2000 04:00:00



Quote:> I have found out that NaN is not supported by gcc under FreeBSD. But FreeBSD
> is supposed to support IEEE float point standard 754, right?

$ gcc nan.c -onan
$ ./nan
d = NaN
d is not a number!
$ cat nan.c
#include <stdio.h>
#include <math.h>

int
main(void)
{
    unsigned long long x = 0xFFFFFFFFFFFFFFFFU;
    double *d = (double *)&x;
    printf("*d = %f\n",*d);

    if (isnan(*d))
    {
        printf("*d is not a number!\n");
    }
    else
    {
        printf("*d IS a number!\n");
    }

    return 0;

Quote:}

$ gcc --version
2.95.2
$ uname -sr
FreeBSD 3.5-STABLE

--

http://www.naisbodo.com/

 
 
 

IEEE float pont support in FreeBSD and GCC

Post by Thoma » Tue, 05 Dec 2000 04:00:00


Sorry, I should list my code:
==================================================================
#include <stdio.h>

int main()
{
        double z = 1.0/0.0;
        double x = z/z;

        fprintf(stdout, "Hello\n");
        fflush(stdout);
        fprintf(stdout, "z %e\n", 1.0/(1.0 - 1.0));
        fflush(stdout);
        fprintf(stdout, "Hello\n");
        fflush(stdout);
        fprintf(stdout, "x %e\n", x);
        fflush(stdout);

        return 0;

Quote:}

====================================================================
Under WIN32, I get:
Hello
z Inf
Hello
x NaN
But under FreeBSD, I get:
Floating exception(core dumped)

I guess I should turn on some option or configuration under FreeBSD. Could
someone help me?

Thanks,
Thomas


> I wonder how exactly you found out that NaN is not supported. So far I've
been
> finding out that it is supported quite well (i.e. it's there)


> > Hi,
> > I have found out that NaN is not supported by gcc under FreeBSD. But
FreeBSD
> > is supposed to support IEEE float point standard 754, right?

> > thanks,
> > Thomas

 
 
 

IEEE float pont support in FreeBSD and GCC

Post by Loren James Ritt » Wed, 06 Dec 2000 04:00:00




Quote:> #include <stdio.h>

> int main()
> {
>        double z = 1.0/0.0;
>        double x = z/z;
[...]
>        return 0;
> }

You forgot to tell us which version of FreeBSD you are using and if
you are using the system compiler (i.e. shipped with the system) or a
compiler added "aftermarket".  Given the exact problem you found, I
can guess which version of FreeBSD you aren't using given the
information I provide below. ;-)

Quote:> I guess I should turn on some option or configuration under FreeBSD. Could
> someone help me?

You have hit a known problem (at least to me, one of your friendly gcc
maintainers for FreeBSD) with FreeBSD 3.4.  I don't know how far back
it goes or exactly when it was fixed, or by whom.  I do know that the
problem was in FreeBSD not gcc sources and was fixed by FreeBSD
4.2-RELEASE, thus I suggest upgrading your system.

With your code (in these environments), I see:

On FreeBSD/alpha 4.2-BETA with system compiler:

; /usr/bin/gcc t.c
; ./a.out
floating point exception--core dumped
; /usr/bin/gcc -mieee t.c
; ./a.out
Hello
z Inf
Hello
x NaN

On FreeBSD/alpha 4.2-BETA with 20001201 snapshot from GNU CVS archive:

; /usr/local/beta-gcc/bin/gcc  t.c
; ./a.out
floating point exception--core dumped
; /usr/local/beta-gcc/bin/gcc  -mieee t.c
; ./a.out
Hello
z Inf
Hello
x NaN

On FreeBSD/i386 3.4 with system compiler, 2.95.2, and 20001129 snapshot:



floating point exception--core dumped

[I could find no obvious option to make this work without a core dump.]

On FreeBSD/i386 4.2-RELEASE with system compiler and 20001120 snapshot:



Hello
z Inf
Hello
x NaN

Regards,
Loren
--
Loren J. Rittle
Staff Software Engineer, Distributed Object Technology Lab
Networks and Infrastructure Research Lab (IL02/2240), Motorola Labs

 
 
 

IEEE float pont support in FreeBSD and GCC

Post by Nick Hilliar » Wed, 06 Dec 2000 04:00:00


[...]

Quote:> Under WIN32, I get:
> Hello
> z Inf
> Hello
> x NaN
> But under FreeBSD, I get:
> Floating exception(core dumped)

This is correct - you're dividing by zero, which according to IEEE 754 is a
capital offense.  Before FreeBSD 4.x, the code above will generate SIGFPE and
dump code, because the default floating point exception mask told it to do so.
This behaviour was changed in 4.0 because it was considered to cause unnecessary
grief (the change was made to the value of __INITIAL_NPXCW__ in v1.18 of
/sys/i386/include/npx.h).

Quote:> I guess I should turn on some option or configuration under FreeBSD. Could
> someone help me?

I don't have a 3.x box to try this on, but have you tried compiling your code
with "-mieee-fp"?  Alternatively, you could use wrap the offending code in
fpgetmask()/fpsetmask() calls, which will certainly work, provided you mask off
the relevant exceptions.

See the "IEEE STANDARD 754 Floating-Point Arithmetic" section in math(3m) for
more info on this.

Nick

 
 
 

1. vms float -> ieee float

Hello!  Can some kind soul please send me the ieee floating
point (4-byte) format? (as in bits, meaning, etc -- mantissa,
sign bit, implied leading bit presence, etc).  Or, please tell
me where to find a doc on in on the net.

I'm trying to read vms four-byte floats with an sgi machine
(because vms-style floats is, apparently, what the robot I'm
talking to uses).  Of course, better yet would be code
which converts vms -> ieee and ieee -> vms.

Thank you!
Dr. Chip
--

        Charles E Campbell, Jr, PhD         -[o]-
        Intelligent Robotics Laboratory    / [:] \    The Next Generation
        Goddard Space Flight Center         || ||         In Robotics

2. HiTech notebook with Solaris

3. VM/CMS float conversion to IEEE float for AIX?

4. Anybody has a Matrox MGA-PRO running?

5. does freeBSD support IEEE (firewire) DISK drives?

6. which distro

7. ANSI/IEEE double-precision floating-point arithmetic?

8. Unix Review email

9. IEEE Floating point format

10. Are IEEE floats platform independent?

11. Linux floating point/IEEE Std.745-1985 compliancy

12. IEEE Floating Point significant digits

13. egcs compatibility with IEEE floating point standard