Long double print anomaly on Solaris

Jim McKelvey mckelvey@whippet.jpl.nasa.gov
Sun Jan 31 23:58:00 GMT 1999


This sample program computes and prints out the largest odd integer  
that can be stored in a long double.

egcs prints:

10384593717069655257060992658440192
406fffffffffffffffffffffffffffff

The Sun CC compiler prints:

10384593717069655257060992658440191
406fffffffffffffffffffffffffffff

egcs is wrong, since the number is odd.

uname -a:

SunOS doberman.jpl.nasa.gov 5.5.1 Generic_103640-20 sun4u sparc  
SUNW,Ultra-2

egcs-19990112

#include <fstream.h>
#include <iomanip.h>

union un
{
    long double   ld;
    unsigned char c[16];
};


int main(void)
{
    un          ldtest;
    long double temp;

    ldtest.ld = 0.0L;

    while (1)
    {
        temp = ldtest.ld + ldtest.ld + 1.0L;

        if ((temp - 1.0L) == temp)
        {
            break;
        }

        ldtest.ld = temp;
    }

    cout << setprecision(100) << ldtest.ld << endl;

    for (int i = 0; i < 16; i++)
    {
        cout << setfill('0') << setw(2) << setbase(16) <<  
int(ldtest.c[i]);
    }

    cout << endl;

    return 0;
}



More information about the Gcc mailing list