view gcc/testsuite/gcc.dg/sinatan-1.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children 1830386684a0
line wrap: on
line source

/* { dg-do run } */
/* { dg-options "-Ofast" } */

extern float sinf (float);
extern float cosf (float);
extern float atanf (float);
extern float sqrtf (float);
extern float nextafterf (float, float);
extern double sin (double);
extern double cos (double);
extern double atan (double);
extern double sqrt (double);
extern double nextafter (double, double);
extern long double sinl (long double);
extern long double cosl (long double);
extern long double atanl (long double);
extern long double sqrtl (long double);
extern long double nextafterl (long double, long double);

extern void abort ();

double __attribute__ ((noinline, optimize("Ofast")))
sinatan (double x)
{
    return sin (atan (x));
}

double __attribute__ ((noinline, optimize("Ofast")))
cosatan (double x)
{
    return cos (atan (x));
}

float __attribute__ ((noinline, optimize("Ofast")))
sinatanf(float x)
{
    return sinf (atanf (x));
}

float __attribute__ ((noinline, optimize("Ofast")))
cosatanf(float x)
{
    return cosf (atanf (x));
}

long double __attribute__ ((noinline, optimize("Ofast")))
sinatanl (long double x)
{
    return sinl (atanl (x));
}

long double __attribute__ ((noinline, optimize("Ofast")))
cosatanl (long double x)
{
    return cosl (atanl (x));
}

int
main()
{
    /* Get first x such that 1 + x*x will overflow */
    float fc = nextafterf (sqrtf (__FLT_MAX__ - 1), __FLT_MAX__);
    double c = nextafter (sqrt (__DBL_MAX__ - 1), __DBL_MAX__);
    long double lc = nextafter (sqrtl (__LDBL_MAX__ - 1), __LDBL_MAX__);

    /*  Force move from FPU to memory, otherwise comparison may
        fail due to possible more accurate registers (see 387)  */
    volatile float fy;
    volatile double y;
    volatile long double ly;

    fy = sinatanf (fc);
    y = sinatan (c);
    ly = sinatanl (lc);

    if (fy != 1.f || y != 1 || ly != 1.L)
        abort ();

    fy = cosatanf (fc);
    y = cosatan (c);
    ly = cosatanl (lc);

    if (fy != 0.f || y != 0. || ly != 0.L)
        abort ();

    fy = sinatanf (-fc);
    y = sinatan (-c);
    ly = sinatanl (-lc);

    if (fy != -1.f || y != -1. || ly != -1.L)
        abort ();
    
    fy = cosatanf (-fc);
    y = cosatan (-c);
    ly = cosatanl (-lc);

    if (fy != 0.f || y != 0. || ly != 0.L)
        abort ();

    return 0;
}