summaryrefslogtreecommitdiff
path: root/src/ints
diff options
context:
space:
mode:
Diffstat (limited to 'src/ints')
-rw-r--r--src/ints/cmp.cpp21
-rw-r--r--src/ints/cmp.hpp65
-rw-r--r--src/ints/cmp_test.cpp1461
-rw-r--r--src/ints/udl.cpp21
-rw-r--r--src/ints/udl.hpp222
-rw-r--r--src/ints/udl_test.cpp781
6 files changed, 2571 insertions, 0 deletions
diff --git a/src/ints/cmp.cpp b/src/ints/cmp.cpp
new file mode 100644
index 0000000..60a8fad
--- /dev/null
+++ b/src/ints/cmp.cpp
@@ -0,0 +1,21 @@
+#include "cmp.hpp"
+// cmp.cpp - comparison related operations
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "../poison.hpp"
diff --git a/src/ints/cmp.hpp b/src/ints/cmp.hpp
new file mode 100644
index 0000000..b979c46
--- /dev/null
+++ b/src/ints/cmp.hpp
@@ -0,0 +1,65 @@
+#ifndef TMWA_INTS_CMP_HPP
+#define TMWA_INTS_CMP_HPP
+// cmp.hpp - comparison related operations
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# include "../sanity.hpp"
+
+# include <limits>
+
+namespace ints
+{
+ template<class T, class U>
+ T saturate(const U& v)
+ {
+ typedef std::numeric_limits<T> Tlim;
+ typedef std::numeric_limits<U> Ulim;
+
+ if (Tlim::is_signed == Ulim::is_signed)
+ {
+ if (v > Tlim::max())
+ return Tlim::max();
+ if (v < Tlim::min())
+ return Tlim::min();
+ return v;
+ }
+ else if (Ulim::is_signed)
+ {
+ // from signed to unsigned
+
+ // Not like v < Tlim::min(), even though Tlim::min() == 0
+ if (v < 0)
+ return 0;
+ if (v > Tlim::max())
+ return Tlim::max();
+ return v;
+ }
+ else // Tlim::is_signed
+ {
+ // from unsigned to signed
+ if (v > Tlim::max())
+ return Tlim::max();
+ return v;
+ }
+ }
+} // namespace ints
+
+using ints::saturate;
+
+#endif // TMWA_INTS_CMP_HPP
diff --git a/src/ints/cmp_test.cpp b/src/ints/cmp_test.cpp
new file mode 100644
index 0000000..5767579
--- /dev/null
+++ b/src/ints/cmp_test.cpp
@@ -0,0 +1,1461 @@
+#include "cmp.hpp"
+// cmp_test.cpp - Testsuite for comparison related operations
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <gtest/gtest.h>
+
+#include "../compat/cast.hpp"
+
+#include "../poison.hpp"
+
+// Google Test is *really* slow to compile this file
+#undef EXPECT_EQ
+#define EXPECT_EQ(a, b) assert(a == b)
+
+TEST(ints, sati8)
+{
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x7fULL), saturate<int8_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x7eULL), saturate<int8_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x01ULL), saturate<int8_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x01ULL), saturate<int8_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x01ULL), saturate<int8_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x80ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(-0x01ULL), saturate<int8_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int8_t>(+0x00ULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x01ULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7eULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int8_t>(+0x7fULL), saturate<int8_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, satu8)
+{
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x00ULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x01ULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7eULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x7fULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0x80ULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xfeULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint8_t>(+0xffULL), saturate<uint8_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, sati16)
+{
+ EXPECT_EQ(maybe_cast<int16_t>(-0x80ULL), saturate<int16_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x7fULL), saturate<int16_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x7eULL), saturate<int16_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x01ULL), saturate<int16_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ULL), saturate<int16_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x01ULL), saturate<int16_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7eULL), saturate<int16_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fULL), saturate<int16_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ULL), saturate<int16_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x01ULL), saturate<int16_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7eULL), saturate<int16_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fULL), saturate<int16_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x80ULL), saturate<int16_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0xfeULL), saturate<int16_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0xffULL), saturate<int16_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x7fffULL), saturate<int16_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0100ULL), saturate<int16_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x00ffULL), saturate<int16_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x00feULL), saturate<int16_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0081ULL), saturate<int16_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0080ULL), saturate<int16_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x007fULL), saturate<int16_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0001ULL), saturate<int16_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0000ULL), saturate<int16_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0001ULL), saturate<int16_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007eULL), saturate<int16_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007fULL), saturate<int16_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0080ULL), saturate<int16_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00feULL), saturate<int16_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ffULL), saturate<int16_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0100ULL), saturate<int16_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7ffeULL), saturate<int16_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0000ULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0001ULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007eULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007fULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0080ULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00feULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ffULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0100ULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7ffeULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0100ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x00ffULL), saturate<int16_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x00feULL), saturate<int16_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0081ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0080ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x007fULL), saturate<int16_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0001ULL), saturate<int16_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0000ULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0001ULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007eULL), saturate<int16_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007fULL), saturate<int16_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0080ULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00feULL), saturate<int16_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0100ULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7ffeULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0000ULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0001ULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007eULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007fULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0080ULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00feULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0100ULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7ffeULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x8000ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0100ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x00ffULL), saturate<int16_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x00feULL), saturate<int16_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0081ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0080ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x007fULL), saturate<int16_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(-0x0001ULL), saturate<int16_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0000ULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0001ULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007eULL), saturate<int16_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007fULL), saturate<int16_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0080ULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00feULL), saturate<int16_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0100ULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7ffeULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0000ULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0001ULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007eULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x007fULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0080ULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00feULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x00ffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x0100ULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7ffeULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int16_t>(+0x7fffULL), saturate<int16_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, satu16)
+{
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ULL), saturate<uint16_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ULL), saturate<uint16_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ULL), saturate<uint16_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ULL), saturate<uint16_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ULL), saturate<uint16_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x01ULL), saturate<uint16_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7eULL), saturate<uint16_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fULL), saturate<uint16_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x01ULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7eULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x80ULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xfeULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffULL), saturate<uint16_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0001ULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007eULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007fULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0080ULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00feULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ffULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0100ULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7ffeULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fffULL), saturate<uint16_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0001ULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007eULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007fULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0080ULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00feULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ffULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0100ULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7ffeULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fffULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x8000ULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xfffeULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0001ULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007eULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007fULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0080ULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00feULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ffULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0100ULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7ffeULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fffULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x8000ULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xfffeULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0001ULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007eULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007fULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0080ULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00feULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0100ULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7ffeULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x8000ULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xfffeULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0001ULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007eULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007fULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0080ULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00feULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0100ULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7ffeULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x8000ULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xfffeULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0000ULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0001ULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007eULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x007fULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0080ULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00feULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x00ffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x0100ULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7ffeULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x7fffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0x8000ULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xfffeULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint16_t>(+0xffffULL), saturate<uint16_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, sati32)
+{
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80ULL), saturate<int32_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x7fULL), saturate<int32_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x7eULL), saturate<int32_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x01ULL), saturate<int32_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00ULL), saturate<int32_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x01ULL), saturate<int32_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7eULL), saturate<int32_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fULL), saturate<int32_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00ULL), saturate<int32_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x01ULL), saturate<int32_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7eULL), saturate<int32_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fULL), saturate<int32_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x80ULL), saturate<int32_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0xfeULL), saturate<int32_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0xffULL), saturate<int32_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int32_t>(-0x8000ULL), saturate<int32_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x7fffULL), saturate<int32_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0100ULL), saturate<int32_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00ffULL), saturate<int32_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00feULL), saturate<int32_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0081ULL), saturate<int32_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0080ULL), saturate<int32_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x007fULL), saturate<int32_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0001ULL), saturate<int32_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000ULL), saturate<int32_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0001ULL), saturate<int32_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x007eULL), saturate<int32_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x007fULL), saturate<int32_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0080ULL), saturate<int32_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00feULL), saturate<int32_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00ffULL), saturate<int32_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0100ULL), saturate<int32_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7ffeULL), saturate<int32_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffULL), saturate<int32_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000ULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0001ULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x007eULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x007fULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0080ULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00feULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00ffULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0100ULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7ffeULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x8000ULL), saturate<int32_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0xfffeULL), saturate<int32_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0xffffULL), saturate<int32_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x7fffffffULL), saturate<int32_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00010000ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0000ffffULL), saturate<int32_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0000fffeULL), saturate<int32_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00008001ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00008000ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00007fffULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000100ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x000000ffULL), saturate<int32_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x000000feULL), saturate<int32_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000081ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000080ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0000007fULL), saturate<int32_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000001ULL), saturate<int32_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000000ULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000001ULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007eULL), saturate<int32_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007fULL), saturate<int32_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000080ULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000feULL), saturate<int32_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000ffULL), saturate<int32_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000100ULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007ffeULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007fffULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00008000ULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000fffeULL), saturate<int32_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000ffffULL), saturate<int32_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00010000ULL), saturate<int32_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7ffffffeULL), saturate<int32_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000000ULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000001ULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007eULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007fULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000080ULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000feULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000ffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000100ULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007ffeULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007fffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00008000ULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000fffeULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000ffffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00010000ULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7ffffffeULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x80000000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00010000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0000ffffULL), saturate<int32_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0000fffeULL), saturate<int32_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00008001ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00008000ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00007fffULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000100ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x000000ffULL), saturate<int32_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x000000feULL), saturate<int32_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000081ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000080ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x0000007fULL), saturate<int32_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(-0x00000001ULL), saturate<int32_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000000ULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000001ULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007eULL), saturate<int32_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007fULL), saturate<int32_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000080ULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000feULL), saturate<int32_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000ffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000100ULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007ffeULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007fffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00008000ULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000fffeULL), saturate<int32_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000ffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00010000ULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7ffffffeULL), saturate<int32_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000000ULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000001ULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007eULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000007fULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000080ULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000feULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x000000ffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00000100ULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007ffeULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00007fffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00008000ULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000fffeULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x0000ffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x00010000ULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7ffffffeULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int32_t>(+0x7fffffffULL), saturate<int32_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, satu32)
+{
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ULL), saturate<uint32_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ULL), saturate<uint32_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ULL), saturate<uint32_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ULL), saturate<uint32_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ULL), saturate<uint32_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x01ULL), saturate<uint32_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7eULL), saturate<uint32_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fULL), saturate<uint32_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x01ULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7eULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x80ULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xfeULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffULL), saturate<uint32_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0001ULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x007eULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x007fULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0080ULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00feULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ffULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0100ULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7ffeULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fffULL), saturate<uint32_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0001ULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x007eULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x007fULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0080ULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00feULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00ffULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0100ULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7ffeULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fffULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x8000ULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xfffeULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffULL), saturate<uint32_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000001ULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007eULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007fULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000080ULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000feULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000ffULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000100ULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007ffeULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007fffULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00008000ULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000fffeULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ffffULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00010000ULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7ffffffeULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fffffffULL), saturate<uint32_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000001ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007eULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007fULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000080ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000feULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000ffULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000100ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007ffeULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007fffULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00008000ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000fffeULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ffffULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00010000ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7ffffffeULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fffffffULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x80000000ULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xfffffffeULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000001ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007eULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007fULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000080ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000feULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000ffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000100ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007ffeULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007fffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00008000ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000fffeULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ffffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00010000ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7ffffffeULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fffffffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x80000000ULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xfffffffeULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000000ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000001ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007eULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000007fULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000080ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000feULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x000000ffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00000100ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007ffeULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00007fffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00008000ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000fffeULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x0000ffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x00010000ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7ffffffeULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x7fffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0x80000000ULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xfffffffeULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint32_t>(+0xffffffffULL), saturate<uint32_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, sati64)
+{
+ EXPECT_EQ(maybe_cast<int64_t>(-0x80ULL), saturate<int64_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x7fULL), saturate<int64_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x7eULL), saturate<int64_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x01ULL), saturate<int64_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00ULL), saturate<int64_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x01ULL), saturate<int64_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7eULL), saturate<int64_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fULL), saturate<int64_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00ULL), saturate<int64_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x01ULL), saturate<int64_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7eULL), saturate<int64_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fULL), saturate<int64_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x80ULL), saturate<int64_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0xfeULL), saturate<int64_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0xffULL), saturate<int64_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int64_t>(-0x8000ULL), saturate<int64_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x7fffULL), saturate<int64_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0100ULL), saturate<int64_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00ffULL), saturate<int64_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00feULL), saturate<int64_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0081ULL), saturate<int64_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0080ULL), saturate<int64_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x007fULL), saturate<int64_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0001ULL), saturate<int64_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000ULL), saturate<int64_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0001ULL), saturate<int64_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x007eULL), saturate<int64_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x007fULL), saturate<int64_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0080ULL), saturate<int64_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00feULL), saturate<int64_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00ffULL), saturate<int64_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0100ULL), saturate<int64_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7ffeULL), saturate<int64_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffULL), saturate<int64_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000ULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0001ULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x007eULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x007fULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0080ULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00feULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00ffULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0100ULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7ffeULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x8000ULL), saturate<int64_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0xfffeULL), saturate<int64_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0xffffULL), saturate<int64_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int64_t>(-0x80000000ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x7fffffffULL), saturate<int64_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00010000ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000ffffULL), saturate<int64_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000fffeULL), saturate<int64_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00008001ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00008000ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00007fffULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000100ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x000000ffULL), saturate<int64_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x000000feULL), saturate<int64_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000081ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000080ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000007fULL), saturate<int64_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000001ULL), saturate<int64_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000ULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000001ULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000007eULL), saturate<int64_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000007fULL), saturate<int64_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000080ULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000feULL), saturate<int64_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000ffULL), saturate<int64_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000100ULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00007ffeULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00007fffULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00008000ULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000fffeULL), saturate<int64_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000ffffULL), saturate<int64_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00010000ULL), saturate<int64_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7ffffffeULL), saturate<int64_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffULL), saturate<int64_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000001ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000007eULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000007fULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000080ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000feULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000ffULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000100ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00007ffeULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00007fffULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00008000ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000fffeULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000ffffULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00010000ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7ffffffeULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x80000000ULL), saturate<int64_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0xfffffffeULL), saturate<int64_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0xffffffffULL), saturate<int64_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<int64_t>(-0x8000000000000000ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x7fffffffffffffffULL), saturate<int64_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000100000000ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000000ffffffffULL), saturate<int64_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000000fffffffeULL), saturate<int64_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000080000001ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000080000000ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x000000007fffffffULL), saturate<int64_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000010000ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x000000000000ffffULL), saturate<int64_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x000000000000fffeULL), saturate<int64_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000008001ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000008000ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000007fffULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000000100ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000000000000ffULL), saturate<int64_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x00000000000000feULL), saturate<int64_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000000081ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000000080ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x000000000000007fULL), saturate<int64_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(-0x0000000000000001ULL), saturate<int64_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000000ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000001ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000007eULL), saturate<int64_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000007fULL), saturate<int64_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000080ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000000000feULL), saturate<int64_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000000000ffULL), saturate<int64_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000100ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000007ffeULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000007fffULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000008000ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000fffeULL), saturate<int64_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000ffffULL), saturate<int64_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000010000ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000007ffffffeULL), saturate<int64_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000007fffffffULL), saturate<int64_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000080000000ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000fffffffeULL), saturate<int64_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000ffffffffULL), saturate<int64_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000100000000ULL), saturate<int64_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7ffffffffffffffeULL), saturate<int64_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffffffffffULL), saturate<int64_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000000ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000001ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000007eULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000007fULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000080ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000000000feULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000000000ffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000000100ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000007ffeULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000007fffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000008000ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000fffeULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000000000ffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000000010000ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000007ffffffeULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x000000007fffffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000080000000ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000fffffffeULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x00000000ffffffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x0000000100000000ULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7ffffffffffffffeULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffffffffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffffffffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffffffffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<int64_t>(+0x7fffffffffffffffULL), saturate<int64_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
+
+TEST(ints, satu64)
+{
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ULL), saturate<uint64_t>(maybe_cast<int8_t>( -0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ULL), saturate<uint64_t>(maybe_cast<int8_t>( -0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ULL), saturate<uint64_t>(maybe_cast<int8_t>( -0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ULL), saturate<uint64_t>(maybe_cast<int8_t>( -0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ULL), saturate<uint64_t>(maybe_cast<int8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x01ULL), saturate<uint64_t>(maybe_cast<int8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7eULL), saturate<uint64_t>(maybe_cast<int8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fULL), saturate<uint64_t>(maybe_cast<int8_t>( +0x7fULL)));
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0x00ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x01ULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0x01ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7eULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0x7eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0x7fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x80ULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0x80ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xfeULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0xfeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xffULL), saturate<uint64_t>(maybe_cast<uint8_t>( +0xffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x0081ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( -0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0001ULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x007eULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x007fULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0080ULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00feULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ffULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0100ULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7ffeULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fffULL), saturate<uint64_t>(maybe_cast<int16_t>( +0x7fffULL)));
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x0000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0001ULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x0001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x007eULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x007eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x007fULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0080ULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x0080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00feULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x00feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00ffULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x00ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0100ULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x0100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7ffeULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x7ffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fffULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x7fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x8000ULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0x8000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xfffeULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0xfffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xffffULL), saturate<uint64_t>(maybe_cast<uint16_t>(+0xffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00008001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00000081ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( -0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000001ULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000007eULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000007fULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000080ULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000feULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000ffULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000100ULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00007ffeULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00007fffULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00008000ULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000fffeULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ffffULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00010000ULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7ffffffeULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fffffffULL), saturate<uint64_t>(maybe_cast<int32_t>( +0x7fffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000001ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000007eULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x0000007eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000007fULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x0000007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000080ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00000080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000feULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x000000feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000ffULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000100ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00000100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00007ffeULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00007fffULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00007fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00008000ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00008000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000fffeULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x0000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000ffffULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x0000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00010000ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x00010000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7ffffffeULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x7ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fffffffULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x7fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x80000000ULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0x80000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xfffffffeULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0xfffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xffffffffULL), saturate<uint64_t>(maybe_cast<uint32_t>(+0xffffffffULL)));
+
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000080000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000008001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000000081ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( -0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000001ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000007eULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000007fULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000080ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000000000feULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000000000ffULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000100ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000007ffeULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000007fffULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000008000ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000fffeULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000ffffULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000010000ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000007ffffffeULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000007fffffffULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000080000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000fffffffeULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ffffffffULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000100000000ULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fffffffffffffffULL), saturate<uint64_t>(maybe_cast<int64_t>( +0x7fffffffffffffffULL)));
+
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000000ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000001ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000000001ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000007eULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x000000000000007eULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000007fULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x000000000000007fULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000080ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000000080ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000000000feULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x00000000000000feULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000000000ffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x00000000000000ffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000000100ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000000100ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000007ffeULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000007ffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000007fffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000007fffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000008000ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000008000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000fffeULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x000000000000fffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000000000ffffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x000000000000ffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000000010000ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000000010000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000007ffffffeULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x000000007ffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x000000007fffffffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x000000007fffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000080000000ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000080000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000fffffffeULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x00000000fffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x00000000ffffffffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x00000000ffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x0000000100000000ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x0000000100000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x7ffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x7fffffffffffffffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x7fffffffffffffffULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0x8000000000000000ULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0x8000000000000000ULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xfffffffffffffffeULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0xfffffffffffffffeULL)));
+ EXPECT_EQ(maybe_cast<uint64_t>(+0xffffffffffffffffULL), saturate<uint64_t>(maybe_cast<uint64_t>(+0xffffffffffffffffULL)));
+}
diff --git a/src/ints/udl.cpp b/src/ints/udl.cpp
new file mode 100644
index 0000000..87dac9c
--- /dev/null
+++ b/src/ints/udl.cpp
@@ -0,0 +1,21 @@
+#include "udl.hpp"
+// udl.cpp - user-defined literals for integers.
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "../poison.hpp"
diff --git a/src/ints/udl.hpp b/src/ints/udl.hpp
new file mode 100644
index 0000000..e3e5fcc
--- /dev/null
+++ b/src/ints/udl.hpp
@@ -0,0 +1,222 @@
+#ifndef TMWA_INTS_UDL_HPP
+#define TMWA_INTS_UDL_HPP
+// udl.hpp - user-defined literals for integers.
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# include "../sanity.hpp"
+
+# include <cstdint>
+
+# include <type_traits>
+
+namespace ints
+{
+ namespace
+ {
+ typedef unsigned long long ullong;
+ template<char C>
+ struct CharParser
+ {
+ constexpr static
+ bool is_dec = '0' <= C && C <= '9';
+ constexpr static
+ bool is_upper = 'A' <= C && C <= 'F';
+ constexpr static
+ bool is_lower = 'a' <= C && C <= 'f';
+
+ static_assert(is_dec || is_upper || is_lower, "char base");
+
+ constexpr static
+ ullong value = is_upper ? (C - 'A' + 10) : is_lower ? (C - 'a' + 10) : C - '0';
+ };
+
+ template<ullong base, ullong accum, char... C>
+ struct BaseParser;
+ template<ullong base, ullong accum, char F, char... R>
+ struct BaseParser<base, accum, F, R...>
+ {
+ constexpr static
+ ullong mulled = accum * base;
+ constexpr static
+ ullong add = CharParser<F>::value;
+ static_assert(add < base, "parse base");
+ constexpr static
+ ullong added = mulled + add;
+ static_assert(added > accum || accum == 0, "parse overflow");
+
+ constexpr static
+ ullong value = BaseParser<base, added, R...>::value;
+ };
+ template<ullong base, ullong accum>
+ struct BaseParser<base, accum>
+ {
+ constexpr static
+ ullong value = accum;
+ };
+
+ template<char... C>
+ struct IntParser
+ {
+ constexpr static
+ ullong value = BaseParser<10, 0, C...>::value;
+ };
+
+ template<char... C>
+ struct IntParser<'0', C...>
+ {
+ constexpr static
+ ullong value = BaseParser<8, 0, C...>::value;
+ };
+
+ template<char... C>
+ struct IntParser<'0', 'x', C...>
+ {
+ constexpr static
+ ullong value = BaseParser<16, 0, C...>::value;
+ };
+
+ template<char... C>
+ struct IntParser<'0', 'X', C...>
+ {
+ constexpr static
+ ullong value = BaseParser<16, 0, C...>::value;
+ };
+
+ template<char... C>
+ struct IntParser<'0', 'b', C...>
+ {
+ constexpr static
+ ullong value = BaseParser<2, 0, C...>::value;
+ };
+
+ template<char... C>
+ struct IntParser<'0', 'B', C...>
+ {
+ constexpr static
+ ullong value = BaseParser<2, 0, C...>::value;
+ };
+
+ template<bool S, ullong V>
+ struct SignedMagnitudeConstant
+ {
+ static constexpr
+ bool sign = S;
+ static constexpr
+ ullong magnitude = V;
+
+ template<class T>
+ operator T()
+ {
+ typedef typename std::make_unsigned<T>::type U;
+
+ constexpr bool is_signed = T(-1) < T(0);
+ static_assert(is_signed >= (sign && magnitude), "signed");
+ constexpr ullong max = ullong(U(-1) >> is_signed);
+ static_assert(magnitude <= max || (sign && magnitude == max + 1), "magna");
+ return sign ? T(ullong(-magnitude)) : T(magnitude);
+ }
+ };
+
+ template<bool S1, ullong V1, bool S2, ullong V2>
+ constexpr
+ bool operator == (SignedMagnitudeConstant<S1, V1>, SignedMagnitudeConstant<S2, V2>)
+ {
+ return V1 == V2 && (S1 == S2 || !V1);
+ }
+ template<bool S1, ullong V1, bool S2, ullong V2>
+ constexpr
+ bool operator != (SignedMagnitudeConstant<S1, V1> lhs, SignedMagnitudeConstant<S2, V2> rhs)
+ {
+ return !(lhs == rhs);
+ }
+ template<bool S, ullong V>
+ constexpr
+ SignedMagnitudeConstant<!S, V> operator -(SignedMagnitudeConstant<S, V>)
+ {
+ return {};
+ }
+
+ struct pint8 { int8_t value; int8_t operator +() { return value; } };
+ struct pint16 { int16_t value; int16_t operator +() { return value; } };
+ struct pint32 { int32_t value; int32_t operator +() { return value; } };
+ struct pint64 { int64_t value; int64_t operator +() { return value; } };
+ struct nint8 { int8_t value; int8_t operator -() { return value; } };
+ struct nint16 { int16_t value; int16_t operator -() { return value; } };
+ struct nint32 { int32_t value; int32_t operator -() { return value; } };
+ struct nint64 { int64_t value; int64_t operator -() { return value; } };
+
+ template<char... C>
+ SignedMagnitudeConstant<false, IntParser<C...>::value> operator "" _const()
+ { return {}; }
+
+ template<char... C>
+ constexpr
+ uint8_t operator "" _u8 () { return operator "" _const<C...>(); }
+ template<char... C>
+ constexpr
+ uint16_t operator "" _u16 () { return operator "" _const<C...>(); }
+ template<char... C>
+ constexpr
+ uint32_t operator "" _u32 () { return operator "" _const<C...>(); }
+ template<char... C>
+ constexpr
+ uint64_t operator "" _u64 () { return operator "" _const<C...>(); }
+ template<char... C>
+ constexpr
+ pint8 operator "" _p8 () { return pint8{operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ pint16 operator "" _p16 () { return pint16{operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ pint32 operator "" _p32 () { return pint32{operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ pint64 operator "" _p64 () { return pint64{operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ nint8 operator "" _n8 () { return nint8{-operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ nint16 operator "" _n16 () { return nint16{-operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ nint32 operator "" _n32 () { return nint32{-operator "" _const<C...>()}; }
+ template<char... C>
+ constexpr
+ nint64 operator "" _n64 () { return nint64{-operator "" _const<C...>()}; }
+ } // anonymous namespace
+} // namespace ints
+
+using ints::operator "" _const;
+
+using ints::operator "" _u8;
+using ints::operator "" _u16;
+using ints::operator "" _u32;
+using ints::operator "" _u64;
+using ints::operator "" _p8;
+using ints::operator "" _p16;
+using ints::operator "" _p32;
+using ints::operator "" _p64;
+using ints::operator "" _n8;
+using ints::operator "" _n16;
+using ints::operator "" _n32;
+using ints::operator "" _n64;
+
+#endif // TMWA_INTS_UDL_HPP
diff --git a/src/ints/udl_test.cpp b/src/ints/udl_test.cpp
new file mode 100644
index 0000000..26ea7c3
--- /dev/null
+++ b/src/ints/udl_test.cpp
@@ -0,0 +1,781 @@
+#include "udl.hpp"
+// udl_test.cpp - Testsuite for a user-defined integer suffixes
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <gtest/gtest.h>
+
+#include "../compat/cast.hpp"
+
+#include "../poison.hpp"
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-variable"
+TEST(ints, smc)
+{
+ {
+ ints::SignedMagnitudeConstant<false, 0> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7e> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7e> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7f> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7f> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x80> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x80> i;
+ static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xfe> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xfe> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xff> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xff> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false,0x100> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x100> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7ffe> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7ffe> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7fff> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7fff> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x8000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x8000> i;
+ //static_cast<int8_t>(i);
+ static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xfffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xfffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false,0x10000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x10000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7ffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7ffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7fffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7fffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x80000000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x80000000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xfffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xfffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xffffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xffffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false,0x100000000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ //static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x100000000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7ffffffffffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ //static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7ffffffffffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x7fffffffffffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ //static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x7fffffffffffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0x8000000000000000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ //static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ //static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0x8000000000000000> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xfffffffffffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ //static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ //static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xfffffffffffffffe> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ //static_cast<int64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<false, 0xffffffffffffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ //static_cast<int64_t>(i);
+ //static_cast<uint8_t>(i);
+ //static_cast<uint16_t>(i);
+ //static_cast<uint32_t>(i);
+ static_cast<uint64_t>(i);
+ }
+ {
+ ints::SignedMagnitudeConstant<true, 0xffffffffffffffff> i;
+ //static_cast<int8_t>(i);
+ //static_cast<int16_t>(i);
+ //static_cast<int32_t>(i);
+ //static_cast<int64_t>(i);
+ }
+ {
+ //ints::SignedMagnitudeConstant<false,0x10000000000000000> i;
+ }
+ {
+ //ints::SignedMagnitudeConstant<true, 0x10000000000000000> i;
+ }
+}
+#pragma GCC diagnostic pop
+
+TEST(ints, constant)
+{
+ EXPECT_EQ(0_const, (ints::SignedMagnitudeConstant<false, 0>{}));
+ EXPECT_EQ(1_const, (ints::SignedMagnitudeConstant<false, 1>{}));
+ EXPECT_EQ(1_const, (ints::SignedMagnitudeConstant<false, 1>{}));
+}
+
+TEST(ints, udl8)
+{
+ EXPECT_EQ(0b00000000_u8, maybe_cast<uint8_t>(0b00000000U));
+ EXPECT_EQ(0b00000001_u8, maybe_cast<uint8_t>(0b00000001U));
+ EXPECT_EQ(0b11111110_u8, maybe_cast<uint8_t>(0b11111110U));
+ EXPECT_EQ(0b11111111_u8, maybe_cast<uint8_t>(0b11111111U));
+ EXPECT_EQ(-0b10000000_n8, maybe_cast<int8_t>(-0b10000000));
+ EXPECT_EQ(-0b01111111_n8, maybe_cast<int8_t>(-0b01111111));
+ EXPECT_EQ(-0b00000001_n8, maybe_cast<int8_t>(-0b00000001));
+ EXPECT_EQ(+0b00000000_p8, maybe_cast<int8_t>(0b00000000));
+ EXPECT_EQ(+0b00000001_p8, maybe_cast<int8_t>(0b00000001));
+ EXPECT_EQ(+0b01111110_p8, maybe_cast<int8_t>(0b01111110));
+ EXPECT_EQ(+0b01111111_p8, maybe_cast<int8_t>(0b01111111));
+
+ EXPECT_EQ(0B00000000_u8, maybe_cast<uint8_t>(0B00000000U));
+ EXPECT_EQ(0B00000001_u8, maybe_cast<uint8_t>(0B00000001U));
+ EXPECT_EQ(0B11111110_u8, maybe_cast<uint8_t>(0B11111110U));
+ EXPECT_EQ(0B11111111_u8, maybe_cast<uint8_t>(0B11111111U));
+ EXPECT_EQ(-0B10000000_n8, maybe_cast<int8_t>(-0B10000000));
+ EXPECT_EQ(-0B01111111_n8, maybe_cast<int8_t>(-0B01111111));
+ EXPECT_EQ(-0B00000001_n8, maybe_cast<int8_t>(-0B00000001));
+ EXPECT_EQ(+0B00000000_p8, maybe_cast<int8_t>(0B00000000));
+ EXPECT_EQ(+0B00000001_p8, maybe_cast<int8_t>(0B00000001));
+ EXPECT_EQ(+0B01111110_p8, maybe_cast<int8_t>(0B01111110));
+ EXPECT_EQ(+0B01111111_p8, maybe_cast<int8_t>(0B01111111));
+
+ EXPECT_EQ(0000_u8, maybe_cast<uint8_t>(0000U));
+ EXPECT_EQ(0001_u8, maybe_cast<uint8_t>(0001U));
+ EXPECT_EQ(0376_u8, maybe_cast<uint8_t>(0376U));
+ EXPECT_EQ(0377_u8, maybe_cast<uint8_t>(0377U));
+ EXPECT_EQ(-0200_n8, maybe_cast<int8_t>(-0200));
+ EXPECT_EQ(-0177_n8, maybe_cast<int8_t>(-0177));
+ EXPECT_EQ(-0001_n8, maybe_cast<int8_t>(-0001));
+ EXPECT_EQ(+0000_p8, maybe_cast<int8_t>(0000));
+ EXPECT_EQ(+0001_p8, maybe_cast<int8_t>(0001));
+ EXPECT_EQ(+0176_p8, maybe_cast<int8_t>(0176));
+ EXPECT_EQ(+0177_p8, maybe_cast<int8_t>(0177));
+
+ EXPECT_EQ(0_u8, maybe_cast<uint8_t>(0U));
+ EXPECT_EQ(1_u8, maybe_cast<uint8_t>(1U));
+ EXPECT_EQ(254_u8, maybe_cast<uint8_t>(254U));
+ EXPECT_EQ(255_u8, maybe_cast<uint8_t>(255U));
+ EXPECT_EQ(-128_n8, maybe_cast<int8_t>(-128));
+ EXPECT_EQ(-127_n8, maybe_cast<int8_t>(-127));
+ EXPECT_EQ(-1_n8, maybe_cast<int8_t>(-1));
+ EXPECT_EQ(+0_p8, maybe_cast<int8_t>(0));
+ EXPECT_EQ(+1_p8, maybe_cast<int8_t>(1));
+ EXPECT_EQ(+126_p8, maybe_cast<int8_t>(126));
+ EXPECT_EQ(+127_p8, maybe_cast<int8_t>(127));
+
+ EXPECT_EQ(0x00_u8, maybe_cast<uint8_t>(0x00U));
+ EXPECT_EQ(0x01_u8, maybe_cast<uint8_t>(0x01U));
+ EXPECT_EQ(0xfe_u8, maybe_cast<uint8_t>(0xfeU));
+ EXPECT_EQ(0xff_u8, maybe_cast<uint8_t>(0xffU));
+ EXPECT_EQ(-0x80_n8, maybe_cast<int8_t>(-0x80));
+ EXPECT_EQ(-0x7f_n8, maybe_cast<int8_t>(-0x7f));
+ EXPECT_EQ(-0x01_n8, maybe_cast<int8_t>(-0x01));
+ EXPECT_EQ(+0x00_p8, maybe_cast<int8_t>(0x00));
+ EXPECT_EQ(+0x01_p8, maybe_cast<int8_t>(0x01));
+ EXPECT_EQ(+0x7e_p8, maybe_cast<int8_t>(0x7e));
+ EXPECT_EQ(+0x7f_p8, maybe_cast<int8_t>(0x7f));
+
+ EXPECT_EQ(0X00_u8, maybe_cast<uint8_t>(0X00U));
+ EXPECT_EQ(0X01_u8, maybe_cast<uint8_t>(0X01U));
+ EXPECT_EQ(0XFE_u8, maybe_cast<uint8_t>(0XFEU));
+ EXPECT_EQ(0XFF_u8, maybe_cast<uint8_t>(0XFFU));
+ EXPECT_EQ(-0X80_n8, maybe_cast<int8_t>(-0X80));
+ EXPECT_EQ(-0X7F_n8, maybe_cast<int8_t>(-0X7F));
+ EXPECT_EQ(-0X01_n8, maybe_cast<int8_t>(-0X01));
+ EXPECT_EQ(+0X00_p8, maybe_cast<int8_t>(0X00));
+ EXPECT_EQ(+0X01_p8, maybe_cast<int8_t>(0X01));
+ EXPECT_EQ(+0X7E_p8, maybe_cast<int8_t>(0X7E));
+ EXPECT_EQ(+0X7F_p8, maybe_cast<int8_t>(0X7F));
+}
+
+TEST(ints, udl16)
+{
+ EXPECT_EQ(0b0000000000000000_u16, maybe_cast<uint16_t>(0b0000000000000000U));
+ EXPECT_EQ(0b0000000000000001_u16, maybe_cast<uint16_t>(0b0000000000000001U));
+ EXPECT_EQ(0b1111111111111110_u16, maybe_cast<uint16_t>(0b1111111111111110U));
+ EXPECT_EQ(0b1111111111111111_u16, maybe_cast<uint16_t>(0b1111111111111111U));
+ EXPECT_EQ(-0b1000000000000000_n16, maybe_cast<int16_t>(-0b1000000000000000));
+ EXPECT_EQ(-0b0111111111111111_n16, maybe_cast<int16_t>(-0b0111111111111111));
+ EXPECT_EQ(-0b0000000000000001_n16, maybe_cast<int16_t>(-0b0000000000000001));
+ EXPECT_EQ(+0b0000000000000000_p16, maybe_cast<int16_t>(0b0000000000000000));
+ EXPECT_EQ(+0b0000000000000001_p16, maybe_cast<int16_t>(0b0000000000000001));
+ EXPECT_EQ(+0b0111111111111110_p16, maybe_cast<int16_t>(0b0111111111111110));
+ EXPECT_EQ(+0b0111111111111111_p16, maybe_cast<int16_t>(0b0111111111111111));
+
+ EXPECT_EQ(0B0000000000000000_u16, maybe_cast<uint16_t>(0B0000000000000000U));
+ EXPECT_EQ(0B0000000000000001_u16, maybe_cast<uint16_t>(0B0000000000000001U));
+ EXPECT_EQ(0B1111111111111110_u16, maybe_cast<uint16_t>(0B1111111111111110U));
+ EXPECT_EQ(0B1111111111111111_u16, maybe_cast<uint16_t>(0B1111111111111111U));
+ EXPECT_EQ(-0B1000000000000000_n16, maybe_cast<int16_t>(-0B1000000000000000));
+ EXPECT_EQ(-0B0111111111111111_n16, maybe_cast<int16_t>(-0B0111111111111111));
+ EXPECT_EQ(-0B0000000000000001_n16, maybe_cast<int16_t>(-0B0000000000000001));
+ EXPECT_EQ(+0B0000000000000000_p16, maybe_cast<int16_t>(0B0000000000000000));
+ EXPECT_EQ(+0B0000000000000001_p16, maybe_cast<int16_t>(0B0000000000000001));
+ EXPECT_EQ(+0B0111111111111110_p16, maybe_cast<int16_t>(0B0111111111111110));
+ EXPECT_EQ(+0B0111111111111111_p16, maybe_cast<int16_t>(0B0111111111111111));
+
+ EXPECT_EQ(0000000_u16, maybe_cast<uint16_t>(0000000U));
+ EXPECT_EQ(0000001_u16, maybe_cast<uint16_t>(0000001U));
+ EXPECT_EQ(0177776_u16, maybe_cast<uint16_t>(0177776U));
+ EXPECT_EQ(0177777_u16, maybe_cast<uint16_t>(0177777U));
+ EXPECT_EQ(-0100000_n16, maybe_cast<int16_t>(-0100000));
+ EXPECT_EQ(-0077777_n16, maybe_cast<int16_t>(-0077777));
+ EXPECT_EQ(-0000001_n16, maybe_cast<int16_t>(-0000001));
+ EXPECT_EQ(+000000_p16, maybe_cast<int16_t>(000000));
+ EXPECT_EQ(+000001_p16, maybe_cast<int16_t>(000001));
+ EXPECT_EQ(+077776_p16, maybe_cast<int16_t>(077776));
+ EXPECT_EQ(+077777_p16, maybe_cast<int16_t>(077777));
+
+ EXPECT_EQ(0_u16, maybe_cast<uint16_t>(0U));
+ EXPECT_EQ(1_u16, maybe_cast<uint16_t>(1U));
+ EXPECT_EQ(65534_u16, maybe_cast<uint16_t>(65534U));
+ EXPECT_EQ(65535_u16, maybe_cast<uint16_t>(65535U));
+ EXPECT_EQ(-32768_n16, maybe_cast<int16_t>(-32768));
+ EXPECT_EQ(-32767_n16, maybe_cast<int16_t>(-32767));
+ EXPECT_EQ(-1_n16, maybe_cast<int16_t>(-1));
+ EXPECT_EQ(+0_p16, maybe_cast<int16_t>(0));
+ EXPECT_EQ(+1_p16, maybe_cast<int16_t>(1));
+ EXPECT_EQ(+32766_p16, maybe_cast<int16_t>(32766));
+ EXPECT_EQ(+32767_p16, maybe_cast<int16_t>(32767));
+
+ EXPECT_EQ(0x0000_u16, maybe_cast<uint16_t>(0x0000U));
+ EXPECT_EQ(0x0001_u16, maybe_cast<uint16_t>(0x0001U));
+ EXPECT_EQ(0xfffe_u16, maybe_cast<uint16_t>(0xfffeU));
+ EXPECT_EQ(0xffff_u16, maybe_cast<uint16_t>(0xffffU));
+ EXPECT_EQ(-0x8000_n16, maybe_cast<int16_t>(-0x8000));
+ EXPECT_EQ(-0x7fff_n16, maybe_cast<int16_t>(-0x7fff));
+ EXPECT_EQ(-0x0001_n16, maybe_cast<int16_t>(-0x0001));
+ EXPECT_EQ(+0x0000_p16, maybe_cast<int16_t>(0x0000));
+ EXPECT_EQ(+0x0001_p16, maybe_cast<int16_t>(0x0001));
+ EXPECT_EQ(+0x7ffe_p16, maybe_cast<int16_t>(0x7ffe));
+ EXPECT_EQ(+0x7fff_p16, maybe_cast<int16_t>(0x7fff));
+
+ EXPECT_EQ(0X0000_u16, maybe_cast<uint16_t>(0X0000U));
+ EXPECT_EQ(0X0001_u16, maybe_cast<uint16_t>(0X0001U));
+ EXPECT_EQ(0XFFFE_u16, maybe_cast<uint16_t>(0XFFFEU));
+ EXPECT_EQ(0XFFFF_u16, maybe_cast<uint16_t>(0XFFFFU));
+ EXPECT_EQ(-0X8000_n16, maybe_cast<int16_t>(-0X8000));
+ EXPECT_EQ(-0X7FFF_n16, maybe_cast<int16_t>(-0X7FFF));
+ EXPECT_EQ(-0X0001_n16, maybe_cast<int16_t>(-0X0001));
+ EXPECT_EQ(+0X0000_p16, maybe_cast<int16_t>(0X0000));
+ EXPECT_EQ(+0X0001_p16, maybe_cast<int16_t>(0X0001));
+ EXPECT_EQ(+0X7FFE_p16, maybe_cast<int16_t>(0X7FFE));
+ EXPECT_EQ(+0X7FFF_p16, maybe_cast<int16_t>(0X7FFF));
+}
+
+TEST(ints, udl32)
+{
+ EXPECT_EQ(0b00000000000000000000000000000000_u32, maybe_cast<uint32_t>(0b00000000000000000000000000000000U));
+ EXPECT_EQ(0b00000000000000000000000000000001_u32, maybe_cast<uint32_t>(0b00000000000000000000000000000001U));
+ EXPECT_EQ(0b11111111111111111111111111111110_u32, maybe_cast<uint32_t>(0b11111111111111111111111111111110U));
+ EXPECT_EQ(0b11111111111111111111111111111111_u32, maybe_cast<uint32_t>(0b11111111111111111111111111111111U));
+ EXPECT_EQ(-0b10000000000000000000000000000000_n32, maybe_cast<int32_t>(-0b10000000000000000000000000000000));
+ EXPECT_EQ(-0b01111111111111111111111111111111_n32, maybe_cast<int32_t>(-0b01111111111111111111111111111111));
+ EXPECT_EQ(-0b00000000000000000000000000000001_n32, maybe_cast<int32_t>(-0b00000000000000000000000000000001));
+ EXPECT_EQ(+0b00000000000000000000000000000000_p32, maybe_cast<int32_t>(0b00000000000000000000000000000000));
+ EXPECT_EQ(+0b00000000000000000000000000000001_p32, maybe_cast<int32_t>(0b00000000000000000000000000000001));
+ EXPECT_EQ(+0b01111111111111111111111111111110_p32, maybe_cast<int32_t>(0b01111111111111111111111111111110));
+ EXPECT_EQ(+0b01111111111111111111111111111111_p32, maybe_cast<int32_t>(0b01111111111111111111111111111111));
+
+ EXPECT_EQ(0B00000000000000000000000000000000_u32, maybe_cast<uint32_t>(0B00000000000000000000000000000000U));
+ EXPECT_EQ(0B00000000000000000000000000000001_u32, maybe_cast<uint32_t>(0B00000000000000000000000000000001U));
+ EXPECT_EQ(0B11111111111111111111111111111110_u32, maybe_cast<uint32_t>(0B11111111111111111111111111111110U));
+ EXPECT_EQ(0B11111111111111111111111111111111_u32, maybe_cast<uint32_t>(0B11111111111111111111111111111111U));
+ EXPECT_EQ(-0B10000000000000000000000000000000_n32, maybe_cast<int32_t>(-0B10000000000000000000000000000000));
+ EXPECT_EQ(-0B01111111111111111111111111111111_n32, maybe_cast<int32_t>(-0B01111111111111111111111111111111));
+ EXPECT_EQ(-0B00000000000000000000000000000001_n32, maybe_cast<int32_t>(-0B00000000000000000000000000000001));
+ EXPECT_EQ(+0B00000000000000000000000000000000_p32, maybe_cast<int32_t>(0B00000000000000000000000000000000));
+ EXPECT_EQ(+0B00000000000000000000000000000001_p32, maybe_cast<int32_t>(0B00000000000000000000000000000001));
+ EXPECT_EQ(+0B01111111111111111111111111111110_p32, maybe_cast<int32_t>(0B01111111111111111111111111111110));
+ EXPECT_EQ(+0B01111111111111111111111111111111_p32, maybe_cast<int32_t>(0B01111111111111111111111111111111));
+
+ EXPECT_EQ(000000000000_u32, maybe_cast<uint32_t>(000000000000U));
+ EXPECT_EQ(000000000001_u32, maybe_cast<uint32_t>(000000000001U));
+ EXPECT_EQ(037777777776_u32, maybe_cast<uint32_t>(037777777776U));
+ EXPECT_EQ(037777777777_u32, maybe_cast<uint32_t>(037777777777U));
+ EXPECT_EQ(-020000000000_n32, maybe_cast<int32_t>(-020000000000));
+ EXPECT_EQ(-017777777777_n32, maybe_cast<int32_t>(-017777777777));
+ EXPECT_EQ(-000000000001_n32, maybe_cast<int32_t>(-000000000001));
+ EXPECT_EQ(+000000000000_p32, maybe_cast<int32_t>(000000000000));
+ EXPECT_EQ(+000000000001_p32, maybe_cast<int32_t>(000000000001));
+ EXPECT_EQ(+017777777776_p32, maybe_cast<int32_t>(017777777776));
+ EXPECT_EQ(+017777777777_p32, maybe_cast<int32_t>(017777777777));
+
+ EXPECT_EQ(0_u32, maybe_cast<uint32_t>(0U));
+ EXPECT_EQ(1_u32, maybe_cast<uint32_t>(1U));
+ EXPECT_EQ(4294967294_u32, maybe_cast<uint32_t>(4294967294U));
+ EXPECT_EQ(4294967295_u32, maybe_cast<uint32_t>(4294967295U));
+ EXPECT_EQ(-2147483648_n32, maybe_cast<int32_t>(-2147483648));
+ EXPECT_EQ(-2147483647_n32, maybe_cast<int32_t>(-2147483647));
+ EXPECT_EQ(-1_n32, maybe_cast<int32_t>(-1));
+ EXPECT_EQ(+0_p32, maybe_cast<int32_t>(0));
+ EXPECT_EQ(+1_p32, maybe_cast<int32_t>(1));
+ EXPECT_EQ(+2147483646_p32, maybe_cast<int32_t>(2147483646));
+ EXPECT_EQ(+2147483647_p32, maybe_cast<int32_t>(2147483647));
+
+ EXPECT_EQ(0x00000000_u32, maybe_cast<uint32_t>(0x00000000U));
+ EXPECT_EQ(0x00000001_u32, maybe_cast<uint32_t>(0x00000001U));
+ EXPECT_EQ(0xfffffffe_u32, maybe_cast<uint32_t>(0xfffffffeU));
+ EXPECT_EQ(0xffffffff_u32, maybe_cast<uint32_t>(0xffffffffU));
+ EXPECT_EQ(-0x80000000_n32, maybe_cast<int32_t>(-0x80000000));
+ EXPECT_EQ(-0x7fffffff_n32, maybe_cast<int32_t>(-0x7fffffff));
+ EXPECT_EQ(-0x00000001_n32, maybe_cast<int32_t>(-0x00000001));
+ EXPECT_EQ(+0x00000000_p32, maybe_cast<int32_t>(0x00000000));
+ EXPECT_EQ(+0x00000001_p32, maybe_cast<int32_t>(0x00000001));
+ EXPECT_EQ(+0x7ffffffe_p32, maybe_cast<int32_t>(0x7ffffffe));
+ EXPECT_EQ(+0x7fffffff_p32, maybe_cast<int32_t>(0x7fffffff));
+
+ EXPECT_EQ(0X00000000_u32, maybe_cast<uint32_t>(0X00000000U));
+ EXPECT_EQ(0X00000001_u32, maybe_cast<uint32_t>(0X00000001U));
+ EXPECT_EQ(0XFFFFFFFE_u32, maybe_cast<uint32_t>(0XFFFFFFFEU));
+ EXPECT_EQ(0XFFFFFFFF_u32, maybe_cast<uint32_t>(0XFFFFFFFFU));
+ EXPECT_EQ(-0X80000000_n32, maybe_cast<int32_t>(-0X80000000));
+ EXPECT_EQ(-0X7FFFFFFF_n32, maybe_cast<int32_t>(-0X7FFFFFFF));
+ EXPECT_EQ(-0X00000001_n32, maybe_cast<int32_t>(-0X00000001));
+ EXPECT_EQ(+0X00000000_p32, maybe_cast<int32_t>(0X00000000));
+ EXPECT_EQ(+0X00000001_p32, maybe_cast<int32_t>(0X00000001));
+ EXPECT_EQ(+0X7FFFFFFE_p32, maybe_cast<int32_t>(0X7FFFFFFE));
+ EXPECT_EQ(+0X7FFFFFFF_p32, maybe_cast<int32_t>(0X7FFFFFFF));
+}
+
+TEST(ints, udl64)
+{
+ EXPECT_EQ(0b0000000000000000000000000000000000000000000000000000000000000000_u64, maybe_cast<uint64_t>(0b0000000000000000000000000000000000000000000000000000000000000000U));
+ EXPECT_EQ(0b0000000000000000000000000000000000000000000000000000000000000001_u64, maybe_cast<uint64_t>(0b0000000000000000000000000000000000000000000000000000000000000001U));
+ EXPECT_EQ(0b1111111111111111111111111111111111111111111111111111111111111110_u64, maybe_cast<uint64_t>(0b1111111111111111111111111111111111111111111111111111111111111110U));
+ EXPECT_EQ(0b1111111111111111111111111111111111111111111111111111111111111111_u64, maybe_cast<uint64_t>(0b1111111111111111111111111111111111111111111111111111111111111111U));
+ EXPECT_EQ(-0b1000000000000000000000000000000000000000000000000000000000000000_n64, maybe_cast<int64_t>(-0b1000000000000000000000000000000000000000000000000000000000000000));
+ EXPECT_EQ(-0b0111111111111111111111111111111111111111111111111111111111111111_n64, maybe_cast<int64_t>(-0b0111111111111111111111111111111111111111111111111111111111111111));
+ EXPECT_EQ(-0b0000000000000000000000000000000000000000000000000000000000000001_n64, maybe_cast<int64_t>(-0b0000000000000000000000000000000000000000000000000000000000000001));
+ EXPECT_EQ(+0b0000000000000000000000000000000000000000000000000000000000000000_p64, maybe_cast<int64_t>(0b0000000000000000000000000000000000000000000000000000000000000000));
+ EXPECT_EQ(+0b0000000000000000000000000000000000000000000000000000000000000001_p64, maybe_cast<int64_t>(0b0000000000000000000000000000000000000000000000000000000000000001));
+ EXPECT_EQ(+0b0111111111111111111111111111111111111111111111111111111111111110_p64, maybe_cast<int64_t>(0b0111111111111111111111111111111111111111111111111111111111111110));
+ EXPECT_EQ(+0b0111111111111111111111111111111111111111111111111111111111111111_p64, maybe_cast<int64_t>(0b0111111111111111111111111111111111111111111111111111111111111111));
+
+ EXPECT_EQ(0B0000000000000000000000000000000000000000000000000000000000000000_u64, maybe_cast<uint64_t>(0B0000000000000000000000000000000000000000000000000000000000000000U));
+ EXPECT_EQ(0B0000000000000000000000000000000000000000000000000000000000000001_u64, maybe_cast<uint64_t>(0B0000000000000000000000000000000000000000000000000000000000000001U));
+ EXPECT_EQ(0B1111111111111111111111111111111111111111111111111111111111111110_u64, maybe_cast<uint64_t>(0B1111111111111111111111111111111111111111111111111111111111111110U));
+ EXPECT_EQ(0B1111111111111111111111111111111111111111111111111111111111111111_u64, maybe_cast<uint64_t>(0B1111111111111111111111111111111111111111111111111111111111111111U));
+ EXPECT_EQ(-0B1000000000000000000000000000000000000000000000000000000000000000_n64, maybe_cast<int64_t>(-0B1000000000000000000000000000000000000000000000000000000000000000));
+ EXPECT_EQ(-0B0111111111111111111111111111111111111111111111111111111111111111_n64, maybe_cast<int64_t>(-0B0111111111111111111111111111111111111111111111111111111111111111));
+ EXPECT_EQ(-0B0000000000000000000000000000000000000000000000000000000000000001_n64, maybe_cast<int64_t>(-0B0000000000000000000000000000000000000000000000000000000000000001));
+ EXPECT_EQ(+0B0000000000000000000000000000000000000000000000000000000000000000_p64, maybe_cast<int64_t>(0B0000000000000000000000000000000000000000000000000000000000000000));
+ EXPECT_EQ(+0B0000000000000000000000000000000000000000000000000000000000000001_p64, maybe_cast<int64_t>(0B0000000000000000000000000000000000000000000000000000000000000001));
+ EXPECT_EQ(+0B0111111111111111111111111111111111111111111111111111111111111110_p64, maybe_cast<int64_t>(0B0111111111111111111111111111111111111111111111111111111111111110));
+ EXPECT_EQ(+0B0111111111111111111111111111111111111111111111111111111111111111_p64, maybe_cast<int64_t>(0B0111111111111111111111111111111111111111111111111111111111111111));
+
+ EXPECT_EQ(00000000000000000000000_u64, maybe_cast<uint64_t>(00000000000000000000000U));
+ EXPECT_EQ(00000000000000000000001_u64, maybe_cast<uint64_t>(00000000000000000000001U));
+ EXPECT_EQ(01777777777777777777776_u64, maybe_cast<uint64_t>(01777777777777777777776U));
+ EXPECT_EQ(01777777777777777777777_u64, maybe_cast<uint64_t>(01777777777777777777777U));
+ EXPECT_EQ(-01000000000000000000000_n64, maybe_cast<int64_t>(-01000000000000000000000));
+ EXPECT_EQ(-00777777777777777777777_n64, maybe_cast<int64_t>(-00777777777777777777777));
+ EXPECT_EQ(-00000000000000000000001_n64, maybe_cast<int64_t>(-000000000000000000000001));
+ EXPECT_EQ(+0000000000000000000000_p64, maybe_cast<int64_t>(0000000000000000000000));
+ EXPECT_EQ(+0000000000000000000001_p64, maybe_cast<int64_t>(0000000000000000000001));
+ EXPECT_EQ(+0777777777777777777776_p64, maybe_cast<int64_t>(0777777777777777777776));
+ EXPECT_EQ(+0777777777777777777777_p64, maybe_cast<int64_t>(0777777777777777777777));
+
+ EXPECT_EQ(0_u64, maybe_cast<uint64_t>(0U));
+ EXPECT_EQ(1_u64, maybe_cast<uint64_t>(1U));
+ EXPECT_EQ(18446744073709551614_u64, maybe_cast<uint64_t>(18446744073709551614U));
+ EXPECT_EQ(18446744073709551615_u64, maybe_cast<uint64_t>(18446744073709551615U));
+ EXPECT_EQ(-9223372036854775808_n64, maybe_cast<int64_t>(-9223372036854775808U));
+ EXPECT_EQ(-9223372036854775807_n64, maybe_cast<int64_t>(-9223372036854775807));
+ EXPECT_EQ(-1_n64, maybe_cast<int64_t>(-1));
+ EXPECT_EQ(+0_p64, maybe_cast<int64_t>(0));
+ EXPECT_EQ(+1_p64, maybe_cast<int64_t>(1));
+ EXPECT_EQ(+9223372036854775806_p64, maybe_cast<int64_t>(9223372036854775806));
+ EXPECT_EQ(+9223372036854775807_p64, maybe_cast<int64_t>(9223372036854775807));
+
+ EXPECT_EQ(0x0000000000000000_u64, maybe_cast<uint64_t>(0x0000000000000000U));
+ EXPECT_EQ(0x0000000000000001_u64, maybe_cast<uint64_t>(0x0000000000000001U));
+ EXPECT_EQ(0xfffffffffffffffe_u64, maybe_cast<uint64_t>(0xfffffffffffffffeU));
+ EXPECT_EQ(0xffffffffffffffff_u64, maybe_cast<uint64_t>(0xffffffffffffffffU));
+ EXPECT_EQ(-0x8000000000000000_n64, maybe_cast<int64_t>(-0x8000000000000000));
+ EXPECT_EQ(-0x7fffffffffffffff_n64, maybe_cast<int64_t>(-0x7fffffffffffffff));
+ EXPECT_EQ(-0x0000000000000001_n64, maybe_cast<int64_t>(-0x0000000000000001));
+ EXPECT_EQ(+0x0000000000000000_p64, maybe_cast<int64_t>(0x0000000000000000));
+ EXPECT_EQ(+0x0000000000000001_p64, maybe_cast<int64_t>(0x0000000000000001));
+ EXPECT_EQ(+0x7ffffffffffffffe_p64, maybe_cast<int64_t>(0x7ffffffffffffffe));
+ EXPECT_EQ(+0x7fffffffffffffff_p64, maybe_cast<int64_t>(0x7fffffffffffffff));
+
+ EXPECT_EQ(0X0000000000000000_u64, maybe_cast<uint64_t>(0X0000000000000000U));
+ EXPECT_EQ(0X0000000000000001_u64, maybe_cast<uint64_t>(0X0000000000000001U));
+ EXPECT_EQ(0XFFFFFFFFFFFFFFFE_u64, maybe_cast<uint64_t>(0XFFFFFFFFFFFFFFFEU));
+ EXPECT_EQ(0XFFFFFFFFFFFFFFFF_u64, maybe_cast<uint64_t>(0XFFFFFFFFFFFFFFFFU));
+ EXPECT_EQ(-0X8000000000000000_n64, maybe_cast<int64_t>(-0X8000000000000000));
+ EXPECT_EQ(-0X7FFFFFFFFFFFFFFF_n64, maybe_cast<int64_t>(-0X7FFFFFFFFFFFFFFF));
+ EXPECT_EQ(-0X0000000000000001_n64, maybe_cast<int64_t>(-0X0000000000000001));
+ EXPECT_EQ(+0X0000000000000000_p64, maybe_cast<int64_t>(0X0000000000000000));
+ EXPECT_EQ(+0X0000000000000001_p64, maybe_cast<int64_t>(0X0000000000000001));
+ EXPECT_EQ(+0X7FFFFFFFFFFFFFFE_p64, maybe_cast<int64_t>(0X7FFFFFFFFFFFFFFE));
+ EXPECT_EQ(+0X7FFFFFFFFFFFFFFF_p64, maybe_cast<int64_t>(0X7FFFFFFFFFFFFFFF));
+}