mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2010-12-18, 21:27   #1
tichy
 
Nov 2010

22×19 Posts
Default __float128 / gcc

Hi,

funny thing - just discovered that gcc supports 128-bit IEEE 754 floating type. Probably it is not a speed monster, but maybe someone will find it useful.

Code:
#include <stdio.h>
#include <stdint.h>

#include <endian.h>

typedef union
{
    __float128  val;
    struct
    {
#if __BYTE_ORDER == __BIG_ENDIAN
        uint64_t sign    : 1;
        uint64_t exp     : 15;
        uint64_t frac1   : 48;
        uint64_t frac0   : 64;
#else
        uint64_t frac0   : 64;
        uint64_t frac1   : 48;
        uint64_t exp     : 15;
        uint64_t sign    : 1;
#endif
    } bits;
} qfloat;

int main()
{
    qfloat      foo;
    qfloat      bar;

    foo.val = 65536.0;

    foo.val += 1.0;
    foo.val *= foo.val;

    bar.val = 8191.0;

    printf("%04X %012llX %016llX\n", (uint16_t)foo.bits.exp, (uint64_t)foo.bits.frac1, foo.bits.frac0);

    return 0;
}
tichy is offline   Reply With Quote
Old 2012-09-14, 02:40   #2
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

103×113 Posts
Default

I just tried building my first program using __float128. Most everything builds OK, but I am getting compile-time warnings (have not tried to link yet, since these tell me I'm missing something) which appear to indicate a header file is needed:

warning: implicit declaration of function ‘fabsq’

The math-lib functions are enumerated here, but no mention of "you must include <blah.h>".
ewmayer is offline   Reply With Quote
Old 2012-09-14, 06:48   #3
Random Poster
 
Random Poster's Avatar
 
Dec 2008

179 Posts
Default

Quote:
Originally Posted by ewmayer View Post
I just tried building my first program using __float128. Most everything builds OK, but I am getting compile-time warnings (have not tried to link yet, since these tell me I'm missing something) which appear to indicate a header file is needed:

warning: implicit declaration of function ‘fabsq’

The math-lib functions are enumerated here, but no mention of "you must include <blah.h>".
The examples for the two functions listed under 3 I/O Library Routines do "#include <quadmath.h>". Of course you could also have found it by looking at the list of files that come with libquadmath, or by "fgrep fabsq /usr/include/*.h".
Random Poster is offline   Reply With Quote
Old 2012-09-14, 18:11   #4
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

103×113 Posts
Default

Quote:
Originally Posted by Random Poster View Post
The examples for the two functions listed under 3 I/O Library Routines do "#include <quadmath.h>". Of course you could also have found it by looking at the list of files that come with libquadmath, or by "fgrep fabsq /usr/include/*.h".
Thanks - that is some poorly constructed documentation there, burying absolutely key "what you need to build this" stuff deep inside an I/O-related example.

But I fail to find quadmath.h anywhere on my system (I used 'locate' instead of 'find', since that is much faster, after the one-time expense of building the locate DB). I find other headers I know are there using 'locate', so the utility is working properly. Note I'm using gcc 4.2, which does recognize the __float128 type - do I need something more recent than that?
ewmayer is offline   Reply With Quote
Old 2012-09-15, 06:48   #5
Random Poster
 
Random Poster's Avatar
 
Dec 2008

17910 Posts
Default

Quote:
Originally Posted by ewmayer View Post
Thanks - that is some poorly constructed documentation there, burying absolutely key "what you need to build this" stuff deep inside an I/O-related example.
The documentation looks like a first draft; each function listed should have its own description page. I expect every one of those will mention quadmath.h once they are written.
Quote:
Originally Posted by ewmayer View Post
But I fail to find quadmath.h anywhere on my system (I used 'locate' instead of 'find', since that is much faster, after the one-time expense of building the locate DB). I find other headers I know are there using 'locate', so the utility is working properly. Note I'm using gcc 4.2, which does recognize the __float128 type - do I need something more recent than that?
gcc may provide the data type, but not the functions that use it; you need to install libquadmath for those (I assumed you had already done so, since you knew about its documentation).
Random Poster is offline   Reply With Quote
Reply



All times are UTC. The time now is 07:48.


Sat Jul 17 07:48:36 UTC 2021 up 50 days, 5:35, 1 user, load averages: 1.22, 1.22, 1.28

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.