| 1 |
// P1467R9 - Extended floating-point types and standard names. |
| 2 |
// Variant of ext-floating3.C test with different specific assumptions |
| 3 |
// about float, double, long double. |
| 4 |
// float, double and long double are assumed to be IEEE 754 single, double |
| 5 |
// and quad. |
| 6 |
// { dg-do compile { target { c++23 && { aarch64*-*-* powerpc64le*-*-linux* riscv*-*-* s390*-*-* sparc*-*-linux* } } } } |
| 7 |
// { dg-options "" } |
| 8 |
// { dg-additional-options "-mlong-double-128" { target s390*-*-* sparc*-*-linux* } } |
| 9 |
// { dg-additional-options "-mvsx -mfloat128 -mlong-double-128 -mabi=ieeelongdouble -Wno-psabi" { target powerpc64le*-*-linux* } } |
| 10 |
|
| 11 |
#include "ext-floating.h" |
| 12 |
|
| 13 |
#if !defined(__STDCPP_FLOAT32_T__) \ |
| 14 |
|| !defined(__STDCPP_FLOAT64_T__) || !defined(__STDCPP_FLOAT128_T__) \ |
| 15 |
|| __FLT_MAX_EXP__ != __FLT32_MAX_EXP__ || __FLT_MANT_DIG__ != __FLT32_MANT_DIG__ \ |
| 16 |
|| __DBL_MAX_EXP__ != __FLT64_MAX_EXP__ || __DBL_MANT_DIG__ != __FLT64_MANT_DIG__ \ |
| 17 |
|| __LDBL_MAX_EXP__ != __FLT128_MAX_EXP__ || __LDBL_MANT_DIG__ != __FLT128_MANT_DIG__ |
| 18 |
#error Unexpected set of floating point types |
| 19 |
#endif |
| 20 |
|
| 21 |
using namespace std; |
| 22 |
|
| 23 |
#ifdef __STDCPP_FLOAT16_T__ |
| 24 |
float16_t f16i = 1.0f; // { dg-warning "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from 'float' with greater conversion rank" "" { target float16 } } |
| 25 |
float16_t f16k = 1.0; // { dg-warning "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from 'double' with greater conversion rank" "" { target float16 } } |
| 26 |
float16_t f16m = 1.0L; // { dg-warning "converting to 'std::float16_t' \\\{aka '_Float16'\\\} from 'long double' with greater conversion rank" "" { target float16 } } |
| 27 |
#endif |
| 28 |
float32_t f32i = 1.0f; |
| 29 |
float32_t f32k = 1.0; // { dg-warning "converting to 'std::float32_t' \\\{aka '_Float32'\\\} from 'double' with greater conversion rank" } |
| 30 |
float32_t f32m = 1.0L; // { dg-warning "converting to 'std::float32_t' \\\{aka '_Float32'\\\} from 'long double' with greater conversion rank" } |
| 31 |
float64_t f64i = 1.0f; |
| 32 |
float64_t f64k = 1.0; |
| 33 |
float64_t f64m = 1.0L; // { dg-warning "converting to 'std::float64_t' \\\{aka '_Float64'\\\} from 'long double' with greater conversion rank" } |
| 34 |
float128_t f128i = 1.0f; |
| 35 |
float128_t f128k = 1.0; |
| 36 |
float128_t f128m = 1.0L; |
| 37 |
|
| 38 |
#ifdef __STDCPP_FLOAT16_T__ |
| 39 |
constexpr float16_t f16x = 1.0F16; |
| 40 |
#endif |
| 41 |
constexpr float32_t f32x = 2.0F32; |
| 42 |
constexpr float64_t f64x = 3.0F64; |
| 43 |
constexpr float128_t f128x = 4.0F128; |
| 44 |
constexpr float fx = 5.0f; |
| 45 |
constexpr double dx = 6.0; |
| 46 |
constexpr long double ldx = 7.0L; |
| 47 |
|
| 48 |
constexpr int foo (float32_t) { return 1; } |
| 49 |
constexpr int foo (float64_t) { return 2; } |
| 50 |
constexpr int bar (float) { return 3; } |
| 51 |
constexpr int bar (double) { return 4; } |
| 52 |
constexpr int bar (long double) { return 5; } |
| 53 |
constexpr int baz (float32_t) { return 6; } |
| 54 |
constexpr int baz (float64_t) { return 7; } |
| 55 |
constexpr int baz (float128_t) { return 8; } |
| 56 |
constexpr int qux (float64_t) { return 9; } |
| 57 |
constexpr int qux (float32_t) { return 10; } |
| 58 |
constexpr int fred (long double) { return 11; } |
| 59 |
constexpr int fred (double) { return 12; } |
| 60 |
constexpr int fred (float) { return 13; } |
| 61 |
constexpr int thud (float128_t) { return 14; } |
| 62 |
constexpr int thud (float64_t) { return 15; } |
| 63 |
constexpr int thud (float32_t) { return 16; } |
| 64 |
struct S { |
| 65 |
constexpr operator float32_t () const { return 1.0f32; } |
| 66 |
constexpr operator float64_t () const { return 2.0f64; } |
| 67 |
}; |
| 68 |
struct T { |
| 69 |
constexpr operator float64_t () const { return 3.0f64; } |
| 70 |
constexpr operator float32_t () const { return 4.0f32; } |
| 71 |
}; |
| 72 |
|
| 73 |
void |
| 74 |
test (S s, T t) |
| 75 |
{ |
| 76 |
#ifdef __STDCPP_FLOAT16_T__ |
| 77 |
foo (float16_t (1.0)); // { dg-error "call of overloaded 'foo\\\(std::float16_t\\\)' is ambiguous" "" { target float16 } } |
| 78 |
#endif |
| 79 |
static_assert (foo (float (2.0)) == 1); |
| 80 |
static_assert (foo (double (3.0)) == 2); |
| 81 |
constexpr double x (s); |
| 82 |
static_assert (x == 2.0); |
| 83 |
#ifdef __STDCPP_FLOAT16_T__ |
| 84 |
bar (f16x); // { dg-error "call of overloaded 'bar\\\(const std::float16_t\\\&\\\)' is ambiguous" "" { target float16 } } |
| 85 |
#endif |
| 86 |
static_assert (bar (f32x) == 3); |
| 87 |
static_assert (bar (f64x) == 4); |
| 88 |
static_assert (bar (f128x) == 5); |
| 89 |
static_assert (bar (fx) == 3); |
| 90 |
static_assert (bar (dx) == 4); |
| 91 |
static_assert (bar (ldx) == 5); |
| 92 |
#ifdef __STDCPP_FLOAT16_T__ |
| 93 |
baz (f16x); // { dg-error "call of overloaded 'baz\\\(const std::float16_t\\\&\\\)' is ambiguous" "" { target float16 } } |
| 94 |
#endif |
| 95 |
static_assert (baz (f32x) == 6); |
| 96 |
static_assert (baz (f64x) == 7); |
| 97 |
static_assert (baz (f128x) == 8); |
| 98 |
static_assert (baz (fx) == 6); |
| 99 |
static_assert (baz (dx) == 7); |
| 100 |
static_assert (baz (ldx) == 8); |
| 101 |
#ifdef __STDCPP_FLOAT16_T__ |
| 102 |
qux (float16_t (1.0)); // { dg-error "call of overloaded 'qux\\\(std::float16_t\\\)' is ambiguous" "" { target float16 } } |
| 103 |
#endif |
| 104 |
static_assert (qux (float (2.0)) == 10); |
| 105 |
static_assert (qux (double (3.0)) == 9); |
| 106 |
constexpr double y (t); |
| 107 |
static_assert (y == 3.0); |
| 108 |
#ifdef __STDCPP_FLOAT16_T__ |
| 109 |
fred (f16x); // { dg-error "call of overloaded 'fred\\\(const std::float16_t\\\&\\\)' is ambiguous" "" { target float16 } } |
| 110 |
#endif |
| 111 |
static_assert (fred (f32x) == 13); |
| 112 |
static_assert (fred (f64x) == 12); |
| 113 |
static_assert (fred (f128x) == 11); |
| 114 |
static_assert (fred (fx) == 13); |
| 115 |
static_assert (fred (dx) == 12); |
| 116 |
static_assert (fred (ldx) == 11); |
| 117 |
#ifdef __STDCPP_FLOAT16_T__ |
| 118 |
thud (f16x); // { dg-error "call of overloaded 'thud\\\(const std::float16_t\\\&\\\)' is ambiguous" "" { target float16 } } |
| 119 |
#endif |
| 120 |
static_assert (thud (f32x) == 16); |
| 121 |
static_assert (thud (f64x) == 15); |
| 122 |
static_assert (thud (f128x) == 14); |
| 123 |
static_assert (thud (fx) == 16); |
| 124 |
static_assert (thud (dx) == 15); |
| 125 |
static_assert (thud (ldx) == 14); |
| 126 |
} |