[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: no quadmath.h on ppc64 ?



On 17/04/18 09:53 AM, Gabriel F. T. Gomes wrote:
Hi, Dennis.

On Tue, 17 Apr 2018, Dennis Clarke wrote:

nix$ cat pq.c

Where does this test case file come from?


Are you asking the same question over and over again on purpose?

It is a trivial test.  So it came from my coffee cup.

Here .. try this :


#define _XOPEN_SOURCE 600
#include <quadmath.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <locale.h>
#include <sys/utsname.h>

#define BUFLEN 128
int main ( int argc, char *argv[] ) {

    int n, j, precision = FLT128_DIG + 2;
    struct utsname uname_data;
    long double pi = 3.1415926535897932384626433832795028841971693993L;

    char buf[BUFLEN];
    char *obuf;
    size_t buf_len = (size_t) BUFLEN;
    __float128 pi_quad = M_PI;

    setlocale( LC_MESSAGES, "C" );
    if ( uname( &uname_data ) < 0 ) {
        fprintf ( stderr,
                 "WARNING : Could not attain system uname data.\n" );
        perror ( "uname" );
    } else {
        printf ("        system name = %s\n", uname_data.sysname );
        printf ("          node name = %s\n", uname_data.nodename );
        printf ("            release = %s\n", uname_data.release );
        printf ("            version = %s\n", uname_data.version );
        printf ("            machine = %s\n", uname_data.machine );
    }
    printf ("\nsizeof(long double) = %i\n\n", sizeof(long double) );

    /* correct 128 bit big endian hex representation of pi is
     *   0x40 00 92 1f b5 44 42 d1 84 69 89 8c c5 17 01 b8 */

    printf("\naddr \"pi\" is %p\n", &pi );
    printf("\ncontents : " );
    for ( j=0; j<sizeof(long double); j++ )
        printf("%02x ", ((unsigned char *)&pi)[j] );
    printf("\n" );

    printf("%+42.38Lf\n", pi );
    printf(" +3.1415926535897932384626433832795028841971 <- pi\n" );

    printf("\nLets try the supposedly 128-bit __float128 type.\n\n" );

    pi_quad = strtoflt128("3.1415926535897932384626433832795028841971",
                                                                NULL );

    n = quadmath_snprintf( buf, buf_len, "%Qg", pi_quad );

    if ( (size_t)n < buf_len ) {
        printf ( "%s\n", buf );
    }

    n = quadmath_snprintf( NULL, 0, "%+-#46.*Qe", precision, pi_quad );

    if ( n > -1 ) {
        obuf = calloc ( (size_t) (n+1), (size_t)sizeof(unsigned char));
        if ( obuf ) {
            n = quadmath_snprintf ( obuf, (n+1), "%+-#46.*Qe",
                                                  precision, pi_quad );
            printf ( "%s\n", obuf );
            printf ( "also n = %i\n", n );
        } else {
            fprintf ( stderr, "ERROR : calloc failed??.\n" );
            return ( EXIT_FAILURE );
        }
        free ( obuf );
    }
    printf("\n\n&pi_quad addr %p is :\n", &pi_quad );
    printf("\ncontents : 0x" );
    for ( j=0; j<sizeof(__float128); j++ )
        printf("%02x ", ((unsigned char *)&pi_quad)[j] );
    printf("\n" );
    printf("pi value : ");
    printf("0x40 00 92 1f b5 44 42 d1 ");
    printf("84 69 89 8c c5 17 01 b8\n");
    printf("\n or the exact reverse order on little endian boxen\n");

    return ( EXIT_SUCCESS );

}

same coffee cup before you ask.


nix$ grep "FLT128_DIG"
/usr/local/gcc7/lib/gcc/powerpc64-unknown-linux-gnu/7.3.0/include/float.h
#undef FLT128_DIG
#define FLT128_DIG              __FLT128_DIG__

Notice that FLT128_DIG comes from ISO/IEC TS 18661-3, and that standard
states that FLT128_DIG is only defined if you define
__STDC_WANT_IEC_60559_TYPES_EXT__ before including float.h:

   #define __STDC_WANT_IEC_60559_TYPES_EXT__
   #include <float.h>

However, also notice that the standard is about the _Float128 type, not
about __float128 (although these types are somewhat related to each other).


Well they are both tossed around so easily.  One of them seems to be the
actual standard and the other seems to be a glibc/gcc idea made up out
of thin air.

nix$ /usr/local/gcc7/bin/gcc -v -m64 -g -S -o pq.s pq.c

To get compiler support for the __float128 type, you also need to pass
-mfloat128 to the compiler.

Nope. There is no libquadmath nor a quadmath.h so nothing compiles in any case.

dc


Reply to: