1 // { dg-do compile { target c++26 } }
3 // C++26 Saturation arithmetic [numerics.sat]
9 static_assert(std::saturate_cast
<unsigned char>(999) == 255);
10 static_assert(std::saturate_cast
<signed char>(999) == 127);
12 static_assert(std::saturate_cast
<unsigned short>(999) == 999);
13 static_assert(std::saturate_cast
<signed short>(999) == 999);
14 static_assert(std::saturate_cast
<short>(INT_MAX
) == SHRT_MAX
);
15 static_assert(std::saturate_cast
<short>(UINT_MAX
) == SHRT_MAX
);
16 static_assert(std::saturate_cast
<short>(UINT_MAX
) == SHRT_MAX
);
17 static_assert(std::saturate_cast
<unsigned short>(UINT_MAX
) == USHRT_MAX
);
18 static_assert(std::saturate_cast
<int>(UINT_MAX
) == INT_MAX
);
19 static_assert(std::saturate_cast
<int>(INT_MAX
) == INT_MAX
);
20 static_assert(std::saturate_cast
<unsigned>(-1) == 0);
21 static_assert(std::saturate_cast
<unsigned>(INT_MIN
) == 0);
22 static_assert(std::saturate_cast
<unsigned>(UINT_MAX
) == UINT_MAX
);
23 static_assert(std::saturate_cast
<unsigned>(LLONG_MAX
) == UINT_MAX
);
24 static_assert(std::saturate_cast
<unsigned>(ULLONG_MAX
) == UINT_MAX
);