/* { dg-options "-std=gnu99 -O0" } */
|
/* { dg-options "-std=gnu99 -O0" } */
|
|
|
/* N1150 5.2 Conversions among decimal floating types and between
|
/* N1150 5.2 Conversions among decimal floating types and between
|
decimal floating types and generic floating types.
|
decimal floating types and generic floating types.
|
C99 6.3.1.5(3) New.
|
C99 6.3.1.5(3) New.
|
|
|
Test various conversions involving decimal floating types. */
|
Test various conversions involving decimal floating types. */
|
|
|
#include <decfloat.h>
|
#include <decfloat.h>
|
|
|
extern void abort (void);
|
extern void abort (void);
|
|
|
volatile _Decimal32 d32;
|
volatile _Decimal32 d32;
|
volatile _Decimal64 d64;
|
volatile _Decimal64 d64;
|
volatile _Decimal128 d128;
|
volatile _Decimal128 d128;
|
|
|
int
|
int
|
main ()
|
main ()
|
{
|
{
|
/* Conversions to larger types. */
|
/* Conversions to larger types. */
|
d32 = 123.4df;
|
d32 = 123.4df;
|
d64 = d32;
|
d64 = d32;
|
if (d64 != 123.4dd)
|
if (d64 != 123.4dd)
|
abort ();
|
abort ();
|
d128 = d32;
|
d128 = d32;
|
if (d128 != 123.4dl)
|
if (d128 != 123.4dl)
|
abort ();
|
abort ();
|
d64 = 345.678dd;
|
d64 = 345.678dd;
|
d128 = d64;
|
d128 = d64;
|
if (d128 != 345.678dl)
|
if (d128 != 345.678dl)
|
abort ();
|
abort ();
|
|
|
/* Conversions to smaller types for which the value fits. */
|
/* Conversions to smaller types for which the value fits. */
|
d64 = 3456.789dd;
|
d64 = 3456.789dd;
|
d32 = d64;
|
d32 = d64;
|
if (d32 != 3456.789df)
|
if (d32 != 3456.789df)
|
abort ();
|
abort ();
|
d128 = 123.4567dl;
|
d128 = 123.4567dl;
|
d32 = d128;
|
d32 = d128;
|
if (d32 != 123.4567dl)
|
if (d32 != 123.4567dl)
|
abort ();
|
abort ();
|
|
|
d128 = 1234567890.123456dl;
|
d128 = 1234567890.123456dl;
|
d64 = d128;
|
d64 = d128;
|
if (d64 != 1234567890.123456dd)
|
if (d64 != 1234567890.123456dd)
|
abort ();
|
abort ();
|
|
|
/* Test demotion to non-representable decimal floating type. */
|
/* Test demotion to non-representable decimal floating type. */
|
|
|
/* Assumes a default rounding mode of 'near'. This uses the rules
|
/* Assumes a default rounding mode of 'near'. This uses the rules
|
describe in the 27 July 2005 draft of IEEE 754r, which are much
|
describe in the 27 July 2005 draft of IEEE 754r, which are much
|
more clear that what's described in draft 5 of N1107. */
|
more clear that what's described in draft 5 of N1107. */
|
|
|
/* Rounds to what _Decimal32 can handle. */
|
/* Rounds to what _Decimal32 can handle. */
|
d64 = 9.99999949E96DD;
|
d64 = 9.99999949E96DD;
|
d32 = d64;
|
d32 = d64;
|
if (d32 != DEC32_MAX)
|
if (d32 != DEC32_MAX)
|
abort();
|
abort();
|
|
|
/* Rounds to more than _Decimal32 can handle. */
|
/* Rounds to more than _Decimal32 can handle. */
|
d64 = 9.9999995E96DD;
|
d64 = 9.9999995E96DD;
|
d32 = d64;
|
d32 = d64;
|
if (d32 != __builtin_infd32())
|
if (d32 != __builtin_infd32())
|
abort();
|
abort();
|
|
|
/* Rounds to what _Decimal32 can handle. */
|
/* Rounds to what _Decimal32 can handle. */
|
d128 = 9.99999949E96DD;
|
d128 = 9.99999949E96DD;
|
d32 = d128;
|
d32 = d128;
|
if (d32 != DEC32_MAX)
|
if (d32 != DEC32_MAX)
|
abort();
|
abort();
|
|
|
/* Rounds to more than _Decimal32 can handle. */
|
/* Rounds to more than _Decimal32 can handle. */
|
d128= 9.9999995E96DD;
|
d128= 9.9999995E96DD;
|
d32 = d128;
|
d32 = d128;
|
if (d32 != __builtin_infd32())
|
if (d32 != __builtin_infd32())
|
abort();
|
abort();
|
|
|
/* Rounds to what _Decimal64 can handle. */
|
/* Rounds to what _Decimal64 can handle. */
|
d128 = 9.99999999999999949E384DL;
|
d128 = 9.99999999999999949E384DL;
|
d64 = d128;
|
d64 = d128;
|
if (d64 != DEC64_MAX)
|
if (d64 != DEC64_MAX)
|
abort();
|
abort();
|
|
|
/* Rounds to more than _Decimal64 can handle. */
|
/* Rounds to more than _Decimal64 can handle. */
|
d128 = 9.9999999999999995E384DL;
|
d128 = 9.9999999999999995E384DL;
|
d64 = d128;
|
d64 = d128;
|
if (d64 != __builtin_infd64())
|
if (d64 != __builtin_infd64())
|
abort();
|
abort();
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|