mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Linux (https://www.mersenneforum.org/forumdisplay.php?f=39)
-   -   __float128 / gcc (https://www.mersenneforum.org/showthread.php?t=14419)

tichy 2010-12-18 21:27

__float128 / gcc
 
Hi,

funny thing - just discovered that gcc supports [URL="http://en.wikipedia.org/wiki/Quadruple_precision_floating-point_format"]128-bit IEEE 754 floating type[/URL]. 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;
}
[/CODE]

ewmayer 2012-09-14 02:40

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:
[i]
warning: implicit declaration of function ‘fabsq’
[/i]
The math-lib functions are enumerated [url=http://gcc.gnu.org/onlinedocs/libquadmath/]here[/url], but no mention of "you must include <blah.h>".

Random Poster 2012-09-14 06:48

[QUOTE=ewmayer;311531]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:
[I]
warning: implicit declaration of function ‘fabsq’
[/I]
The math-lib functions are enumerated [URL="http://gcc.gnu.org/onlinedocs/libquadmath/"]here[/URL], but no mention of "you must include <blah.h>".[/QUOTE]
The examples for the two functions listed under [URL="http://gcc.gnu.org/onlinedocs/libquadmath/index.html#toc_I_002fO-Library-Routines"]3 I/O Library Routines[/URL] 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".

ewmayer 2012-09-14 18:11

[QUOTE=Random Poster;311557]The examples for the two functions listed under [URL="http://gcc.gnu.org/onlinedocs/libquadmath/index.html#toc_I_002fO-Library-Routines"]3 I/O Library Routines[/URL] 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".[/QUOTE]

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?

Random Poster 2012-09-15 06:48

[QUOTE=ewmayer;311626]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.[/QUOTE]
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=ewmayer;311626]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?[/QUOTE]
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).


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

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