19#include "ns3/int64x64.h"
21#include "ns3/valgrind.h"
32#define RUNNING_WITH_LIMITED_PRECISION 1
37#define RUNNING_WITH_LIMITED_PRECISION RUNNING_ON_VALGRIND
76 Printer(
const int64_t high,
const uint64_t low)
118 os << std::fixed << std::setprecision(22) << p.
m_value;
121 os << std::hex << std::setfill(
'0') <<
" (0x" << std::setw(16) << p.
m_high <<
" 0x"
122 << std::setw(16) << p.
m_low <<
")" << std::dec << std::setfill(
' ');
135 void DoRun()
override;
141 void Check(
const int64_t hi,
const uint64_t lo);
145 :
TestCase(
"Manipulate the high and low part of every number")
152 uint64_t tolerance = 0;
160 uint64_t vLow = value.GetLow();
161 bool pass = ((value.GetHigh() == hi) && ((
Max(vLow, lo) -
Min(vLow, lo)) <= tolerance));
163 std::cout <<
GetParent()->
GetName() <<
" Check: " << (pass ?
"pass " :
"FAIL ")
168 "High part does not match for hi:" << hi <<
" lo: " << lo);
172 "Low part does not match for hi: " << hi <<
" lo: " << lo);
178 std::cout << std::endl;
185 low =
static_cast<uint64_t
>(
HP_MAX_64 * std::numeric_limits<long double>::epsilon());
190 Check(0, 0xffffffffffffffffULL - low);
194 Check(1, 0xffffffffffffffffULL - low);
198 Check(-1, 0xffffffffffffffffULL - low);
210 void DoRun()
override;
217 void Check(
const int64x64_t value,
const int64_t expectInt,
const int64_t expectRnd);
221 :
TestCase(
"Check GetInt and Round")
227 const int64_t expectInt,
228 const int64_t expectRnd)
230 int64_t vInt = value.GetInt();
231 int64_t vRnd = value.Round();
233 bool pass = (vInt == expectInt) && (vRnd == expectRnd);
234 std::cout <<
GetParent()->
GetName() <<
" Check: " << (pass ?
"pass " :
"FAIL ") << value
235 <<
" (int)-> " << std::setw(2) << vInt <<
" (expected: " << std::setw(2) << expectInt
236 <<
"), (rnd)-> " << std::setw(2) << vRnd <<
" (expected " << std::setw(2) << expectRnd
246 std::cout << std::endl;
275 void DoRun()
override;
283 void Check(
const std::string& str,
286 const int64_t tolerance = 0);
290 :
TestCase(
"Parse int64x64_t numbers as strings")
298 const int64_t tolerance )
301 std::istringstream iss;
306 std::string input =
"\"" + str +
"\"";
307 uint64_t vLow = value.GetLow();
308 bool pass = ((value.GetHigh() == hi) && (
Max(vLow, lo) -
Min(vLow, lo) <= tolerance));
310 std::cout <<
GetParent()->
GetName() <<
" Input: " << (pass ?
"pass " :
"FAIL ") << std::left
311 << std::setw(28) << input << std::right <<
Printer(value)
312 <<
" expected: " <<
Printer(hi, lo) <<
" +/- " << tolerance << std::endl;
316 "High parts do not match for input string \"" << str <<
"\"");
320 "Low parts do not match for input string \"" << str <<
"\"");
326 std::cout << std::endl;
329 int64_t tolerance = 0;
341 Check(
"001.0", 1, 0);
342 Check(
"+001.0", 1, 0);
343 Check(
"020.0", 20, 0);
344 Check(
"+020.0", 20, 0);
345 Check(
"1.0000000", 1, 0);
346 Check(
"-1.0", -1, 0, tolerance);
347 Check(
"-1.0000", -1, 0, tolerance);
348 Check(
" 1.000000000000000000054", 1, 1, tolerance);
349 Check(
"-1.000000000000000000054", (int64_t)-2, (uint64_t)-1, tolerance);
363 void DoRun()
override;
369 void Check(
const std::string& str,
const int64_t tolerance = 0);
373 :
TestCase(
"Roundtrip int64x64_t numbers as strings")
380 std::stringstream iss(str);
384 std::stringstream oss;
385 oss << std::scientific << std::setprecision(21) << expect;
389 bool pass =
Abs(value - expect) <=
int64x64_t(0, tolerance + 1);
391 std::string input =
"\"" + str +
"\"";
392 std::string output =
"\"" + oss.str() +
"\"";
396 std::cout <<
GetParent()->
GetName() <<
" InputOutput: " << (pass ?
"pass " :
"FAIL ")
397 <<
" in: " << std::left << std::setw(28) << input <<
" out: " << std::left
398 << std::setw(28) << output << std::right << std::endl;
402 std::cout <<
GetParent()->
GetName() <<
" InputOutput: " << (pass ?
"pass " :
"FAIL ")
403 <<
" in: " << std::left << std::setw(28) << input << std::right
404 <<
Printer(expect) << std::endl;
406 <<
" out: " << std::left << std::setw(28) << output << std::right
407 <<
Printer(value) << std::endl;
413 "Converted string does not match expected string");
419 std::cout << std::endl;
422 int64_t tolerance = 0;
429 Check(
"+1.000000000000000000000");
430 Check(
"+20.000000000000000000000");
431 Check(
"+0.000000000000000000000", tolerance);
432 Check(
"-1.000000000000000000000", tolerance);
433 Check(
"+1.084467440737095516158", tolerance);
434 Check(
"-2.084467440737095516158", tolerance);
435 Check(
"+3.184467440737095516179", tolerance);
436 Check(
"-4.184467440737095516179", tolerance);
448 void DoRun()
override;
463 :
TestCase(
"Basic arithmetic operations")
473 bool pass =
Abs(value - expect) <= tolerance;
476 <<
": " << value <<
" == " << expect <<
" (+/- " << tolerance <<
")" << std::endl;
490 std::cout << std::endl;
513 Check(17, one * one, one);
514 Check(18, one * (-one), -one);
515 Check(19, (-one) * (-one), one);
523 Check(21, frac, 0.75);
524 Check(22, fplf2, 1.3125);
532 Check(23, zerof, frac);
535 Check(25, zerof - onef, -one);
537 Check(27, onef - twof, -one);
538 Check(28, onef - (-onef), twof + frac);
539 Check(29, (-onef) - (-twof), one);
540 Check(30, (-onef) - twof, -thref - frac);
542 Check(31, zerof + zerof, zerof + frac);
543 Check(32, zerof + onef, onef + frac);
544 Check(33, onef + onef, twof + frac);
545 Check(34, onef + twof, thref + frac);
547 Check(36, (-onef) + (-twof), -thref - frac);
548 Check(37, (-onef) + twof, one);
550 Check(38, zerof * zerof, frac * frac);
552 Check(40, zerof * one, frac);
554 Check(41, zerof * onef, fplf2);
555 Check(42, zerof * (-onef), -fplf2);
556 Check(43, onef * onef, onef + fplf2);
557 Check(44, onef * (-onef), -onef - fplf2);
558 Check(45, (-onef) * (-onef), onef + fplf2);
563 Check(47, (twof * thref) / thref, twof);
567 Check(49, (twof / thref) * thref, twof, 3 * tol1);
574 int64x64_t(1999999999, 0xfffffffffffffffeULL));
579 auto x =
int64x64_t(std::numeric_limits<int64_t>::min(), 0);
584 int64x64_t x(1 << 30, (
static_cast<uint64_t
>(1) << 63) + 1);
586 int64x64_t expected(1152921505680588800, 4611686020574871553);
593 Check(54, ret, expected, tolerance);
620 void DoRun()
override;
627 void Check(
const double result,
const double expect,
const std::string& msg);
638 bool pass = result == expect;
640 std::cout <<
GetParent()->
GetName() <<
" Bug 455: " << (pass ?
"pass " :
"FAIL ")
641 <<
"res: " << result <<
" exp: " << expect <<
": " << msg << std::endl;
649 std::cout << std::endl;
662 Check(a.
GetDouble(), -2.5,
"Test sign, first operation negative");
684 void DoRun()
override;
691 void Check(
const double result,
const double expect,
const std::string& msg);
702 bool pass = result == expect;
704 std::cout <<
GetParent()->
GetName() <<
" Bug 863: " << (pass ?
"pass " :
"FAIL ")
705 <<
"res: " << result <<
" exp: " << expect <<
": " << msg << std::endl;
713 std::cout << std::endl;
725 Check(a.
GetDouble(), -0.5,
"Check that we actually convert doubles correctly");
750 void DoRun()
override;
757 void Check(
const uint64_t low,
const std::string& value,
const int64_t tolerance = 0);
761 :
TestCase(
"Test case for bug 1786")
767 const std::string& str,
768 const int64_t tolerance )
771 std::ostringstream oss;
772 oss << std::scientific << std::setprecision(22) << value;
776 bool pass = oss.str() == str;
778 std::cout <<
GetParent()->
GetName() <<
" Bug 1786: " << (pass ?
"pass " :
"FAIL ")
779 <<
" 0x" << std::hex << std::setw(16) << low << std::dec <<
" = " << oss.str();
782 std::cout <<
", expected " << str;
784 std::cout << std::endl;
794 <<
" 0x" << std::hex << std::setw(16) << low << std::dec <<
" = " << oss.str()
795 <<
", expected " << str << std::endl;
802 std::cout << std::endl;
805 int64_t tolerance = 0;
819 Check( 1ULL,
"+0.0000000000000000000542");
820 Check( 2ULL,
"+0.0000000000000000001084");
821 Check( 3ULL,
"+0.0000000000000000001626");
822 Check( 4ULL,
"+0.0000000000000000002168");
823 Check( 5ULL,
"+0.0000000000000000002710");
824 Check( 6ULL,
"+0.0000000000000000003253");
825 Check( 7ULL,
"+0.0000000000000000003795");
826 Check( 8ULL,
"+0.0000000000000000004337");
827 Check( 9ULL,
"+0.0000000000000000004879");
828 Check( 0xAULL,
"+0.0000000000000000005421");
829 Check( 0xFULL,
"+0.0000000000000000008132");
830 Check( 0xF0ULL,
"+0.0000000000000000130104");
831 Check( 0xF00ULL,
"+0.0000000000000002081668");
832 Check( 0xF000ULL,
"+0.0000000000000033306691");
833 Check( 0xF0000ULL,
"+0.0000000000000532907052");
834 Check( 0xF00000ULL,
"+0.0000000000008526512829");
835 Check( 0xF000000ULL,
"+0.0000000000136424205266");
836 Check( 0xF0000000ULL,
"+0.0000000002182787284255");
837 Check( 0xF00000000ULL,
"+0.0000000034924596548080");
838 Check( 0xF000000000ULL,
"+0.0000000558793544769287");
839 Check( 0xF0000000000ULL,
"+0.0000008940696716308594");
840 Check( 0xF00000000000ULL,
"+0.0000143051147460937500");
841 Check( 0xF000000000000ULL,
"+0.0002288818359375000000");
842 Check( 0xF0000000000000ULL,
"+0.0036621093750000000000");
843 Check( 0xF00000000000000ULL,
"+0.0585937500000000000000");
844 std::cout << std::endl;
845 Check(0x7FFFFFFFFFFFFFFDULL,
"+0.4999999999999999998374", tolerance);
846 Check(0x7FFFFFFFFFFFFFFEULL,
"+0.4999999999999999998916", tolerance);
847 Check(0x7FFFFFFFFFFFFFFFULL,
"+0.4999999999999999999458", tolerance);
848 Check(0x8000000000000000ULL,
"+0.5000000000000000000000");
849 Check(0x8000000000000001ULL,
"+0.5000000000000000000542", tolerance);
850 Check(0x8000000000000002ULL,
"+0.5000000000000000001084", tolerance);
851 Check(0x8000000000000003ULL,
"+0.5000000000000000001626", tolerance);
852 std::cout << std::endl;
853 Check(0xF000000000000000ULL,
"+0.9375000000000000000000");
854 Check(0xFF00000000000000ULL,
"+0.9960937500000000000000");
855 Check(0xFFF0000000000000ULL,
"+0.9997558593750000000000");
856 Check(0xFFFF000000000000ULL,
"+0.9999847412109375000000");
857 Check(0xFFFFF00000000000ULL,
"+0.9999990463256835937500");
858 Check(0xFFFFFF0000000000ULL,
"+0.9999999403953552246094");
859 Check(0xFFFFFFF000000000ULL,
"+0.9999999962747097015381");
860 Check(0xFFFFFFFF00000000ULL,
"+0.9999999997671693563461");
861 Check(0xFFFFFFFFF0000000ULL,
"+0.9999999999854480847716");
862 Check(0xFFFFFFFFFF000000ULL,
"+0.9999999999990905052982");
863 Check(0xFFFFFFFFFFF00000ULL,
"+0.9999999999999431565811");
864 Check(0xFFFFFFFFFFFF0000ULL,
"+0.9999999999999964472863");
865 Check(0xFFFFFFFFFFFFF000ULL,
"+0.9999999999999997779554");
866 Check(0xFFFFFFFFFFFFFF00ULL,
"+0.9999999999999999861222");
867 Check(0xFFFFFFFFFFFFFFF0ULL,
"+0.9999999999999999991326");
868 Check(0xFFFFFFFFFFFFFFF5ULL,
"+0.9999999999999999994037", tolerance);
869 Check(0xFFFFFFFFFFFFFFF6ULL,
"+0.9999999999999999994579", tolerance);
870 Check(0xFFFFFFFFFFFFFFF7ULL,
"+0.9999999999999999995121", tolerance);
871 Check(0xFFFFFFFFFFFFFFF8ULL,
"+0.9999999999999999995663", tolerance);
872 Check(0xFFFFFFFFFFFFFFF9ULL,
"+0.9999999999999999996205", tolerance);
873 Check(0xFFFFFFFFFFFFFFFAULL,
"+0.9999999999999999996747", tolerance);
874 Check(0xFFFFFFFFFFFFFFFBULL,
"+0.9999999999999999997289", tolerance);
875 Check(0xFFFFFFFFFFFFFFFCULL,
"+0.9999999999999999997832", tolerance);
876 Check(0xFFFFFFFFFFFFFFFDULL,
"+0.9999999999999999998374", tolerance);
877 Check(0xFFFFFFFFFFFFFFFEULL,
"+0.9999999999999999998916", tolerance);
878 Check(0xFFFFFFFFFFFFFFFFULL,
"+0.9999999999999999999458", tolerance);
892 void DoRun()
override;
900 void Check(
const bool result,
const bool expect,
const std::string& msg);
904 :
TestCase(
"Basic compare operations")
911 bool pass = result == expect;
913 std::cout <<
GetParent()->
GetName() <<
" Compare: " << (pass ?
"pass " :
"FAIL ") << msg
922 std::cout << std::endl;
937 Check(zerof == zerof,
true,
"equality, zero");
938 Check(onef == onef,
true,
"equality, positive");
939 Check(mtwof == mtwof,
true,
"equality, negative");
940 Check(
zero == one,
false,
"equality false, zero");
941 Check(one ==
two,
false,
"equality false, unsigned");
942 Check(one == mone,
false,
"equality false, signed");
943 Check(onef == one,
false,
"equality false, fraction");
944 std::cout << std::endl;
946 Check(zerof != zerof,
false,
"inequality, zero");
947 Check(onef != onef,
false,
"inequality, positive");
948 Check(mtwof != mtwof,
false,
"inequality, negative");
949 Check(
zero != one,
true,
"inequality true, zero");
950 Check(one !=
two,
true,
"inequality true, unsigned");
951 Check(one != mone,
true,
"inequality true, signed");
952 Check(onef != one,
true,
"inequality true, fraction");
953 std::cout << std::endl;
955 Check(zerof < onef,
true,
"less, zerof");
957 Check(one < onef,
true,
"less, positive");
958 Check(monef < mone,
true,
"less, negative");
959 Check(onef < one,
false,
"less, false, positive");
960 Check(mtwo < mtwof,
false,
"less, false, negative");
961 std::cout << std::endl;
963 Check(zerof <= zerof,
true,
"less equal, equal, zerof");
964 Check(
zero <= zerof,
true,
"less equal, less, zero");
965 Check(onef <= onef,
true,
"less equal, equal, positive");
966 Check(monef <= mone,
true,
"less equal, less, negative");
967 Check(onef <= one,
false,
"less equal, false, positive");
968 Check(mtwo <= mtwof,
false,
"less equal, false, negative");
969 std::cout << std::endl;
971 Check(onef > zerof,
true,
"greater, zerof");
972 Check(zerof >
zero,
true,
"greater, zero");
973 Check(onef > one,
true,
"greater, positive");
974 Check(mone > monef,
true,
"greater, negative");
975 Check(one > onef,
false,
"greater, false, positive");
976 Check(mtwof > mtwo,
false,
"greater, false, negative");
977 std::cout << std::endl;
979 Check(zerof >= zerof,
true,
"greater equal, equal, zerof");
980 Check(zerof >=
zero,
true,
"greater equal, greater, zero");
981 Check(onef >= onef,
true,
"greater equal, equal, positive");
982 Check(mone >= monef,
true,
"greater equal, greater, negative");
983 Check(one >= onef,
false,
"greater equal, false, positive");
984 Check(mtwof >= mtwo,
false,
"greater equal, false, negative");
985 std::cout << std::endl;
987 Check(
zero ==
false,
true,
"zero == false");
988 Check(one ==
true,
true,
"one == true");
989 Check(zerof !=
false,
true,
"zerof != false");
990 Check((!
zero) ==
true,
true,
"!zero == true");
991 Check((!zerof) ==
false,
true,
"!zerof == false");
992 Check((!one) ==
false,
true,
"!one == false");
993 Check((+onef) == onef,
true,
"unary positive");
994 Check((-onef) == monef,
true,
"unary negative");
1007 void DoRun()
override;
1012 void Check(
const int64_t factor);
1024 const std::string& msg,
1025 const double tolerance = 0);
1029 :
TestCase(
"Invert and MulByInvert")
1037 const std::string& msg,
1038 const double tolerance )
1040 bool pass =
Abs(result - expect) <= tolerance;
1046 std::cout <<
"pass: " << factor <<
": ";
1050 std::cout <<
"FAIL: " << factor <<
": "
1051 <<
"(res: " << result <<
" exp: " << expect <<
" tol: " << tolerance <<
") ";
1053 std::cout << msg << std::endl;
1067 double tolerance = 0;
1071 tolerance = 0.000000000000000001L;
1075 CheckCase(factor, b, one,
"x * x^-1 == 1", tolerance);
1079 CheckCase(factor, c, factorI,
"1 * x^-1 == 1 / x");
1087 CheckCase(factor, e, -one,
"-x * x^-1 == -1", tolerance);
1093 std::cout << std::endl;
1112 Check(10000000000LL);
1113 Check(100000000000LL);
1114 Check(1000000000000LL);
1115 Check(10000000000000LL);
1116 Check(100000000000000LL);
1117 Check(1000000000000000LL);
1129 void DoRun()
override;
1135 void Check(
const int64_t intPart);
1143 void Check(
const long double dec,
1144 const long double frac,
1145 const int64_t intPart,
1202 std::round(1e22 / std::pow(2.0L, std::min(64, LDBL_MANT_DIG))) / 1e22;
1205 :
TestCase(
"Construct from floating point."),
1214 const long double frac,
1215 const int64_t intPart,
1219 long double value = dec + frac;
1279 const bool skip = (frac && (value ==
m_last));
1288 long double epsilon = std::numeric_limits<long double>::epsilon();
1292 long double margin = 0;
1305 epsilon = std::numeric_limits<double>::epsilon();
1309 tolerance = std::max(1.0L, std::fabs(value)) *
epsilon + margin *
epsilon;
1312 const bool pass = delta <= tolerance;
1317 std::ios_base::fmtflags ff = std::cout.flags();
1318 std::cout << std::fixed << std::setprecision(22);
1321 <<
" Double: " << (skip ?
"skip " : (pass ?
"pass " :
"FAIL ")) << std::showpos
1322 << value <<
" == " <<
Printer(result) << (under ?
" (underflow)" :
"") << std::endl;
1327 std::cout <<
GetParent()->
GetName() << std::left << std::setw(43) <<
" expected"
1328 << std::right <<
Printer(expect) << std::endl;
1330 if (delta == tolerance)
1334 <<
" delta = tolerance" << std::right <<
Printer(delta) << std::endl;
1339 std::cout <<
GetParent()->
GetName() << std::left << std::setw(43) <<
" delta"
1340 << std::right <<
Printer(delta) << std::endl;
1342 <<
" tolerance" << std::right <<
Printer(tolerance)
1343 <<
" eps: " <<
epsilon <<
", margin: " << margin << std::endl;
1357 std::cout.flags(ff);
1363 std::cout << std::endl;
1365 <<
"integer: " << intPart << std::endl;
1375 long double v = intPart;
1377 Check(v, 0.0L, intPart, 0x0ULL);
1378 Check(v, 0.0000000000000000000542L, intPart, 0x1ULL);
1379 Check(v, 0.0000000000000000001084L, intPart, 0x2ULL);
1380 Check(v, 0.0000000000000000001626L, intPart, 0x3ULL);
1381 Check(v, 0.0000000000000000002168L, intPart, 0x4ULL);
1382 Check(v, 0.0000000000000000002711L, intPart, 0x5ULL);
1383 Check(v, 0.0000000000000000003253L, intPart, 0x6ULL);
1384 Check(v, 0.0000000000000000003795L, intPart, 0x7ULL);
1385 Check(v, 0.0000000000000000004337L, intPart, 0x8ULL);
1386 Check(v, 0.0000000000000000004879L, intPart, 0x9ULL);
1387 Check(v, 0.0000000000000000005421L, intPart, 0xAULL);
1388 Check(v, 0.0000000000000000005963L, intPart, 0xBULL);
1389 Check(v, 0.0000000000000000006505L, intPart, 0xCULL);
1390 Check(v, 0.0000000000000000007047L, intPart, 0xDULL);
1391 Check(v, 0.0000000000000000007589L, intPart, 0xEULL);
1392 Check(v, 0.0000000000000000008132L, intPart, 0xFULL);
1393 Check(v, 0.0000000000000000130104L, intPart, 0xF0ULL);
1394 Check(v, 0.0000000000000002081668L, intPart, 0xF00ULL);
1395 Check(v, 0.0000000000000033306691L, intPart, 0xF000ULL);
1396 Check(v, 0.0000000000000532907052L, intPart, 0xF0000ULL);
1397 Check(v, 0.0000000000008526512829L, intPart, 0xF00000ULL);
1398 Check(v, 0.0000000000136424205266L, intPart, 0xF000000ULL);
1399 Check(v, 0.0000000002182787284255L, intPart, 0xF0000000ULL);
1400 Check(v, 0.0000000034924596548080L, intPart, 0xF00000000ULL);
1401 Check(v, 0.0000000558793544769287L, intPart, 0xF000000000ULL);
1402 Check(v, 0.0000008940696716308594L, intPart, 0xF0000000000ULL);
1403 Check(v, 0.0000143051147460937500L, intPart, 0xF00000000000ULL);
1404 Check(v, 0.0002288818359375000000L, intPart, 0xF000000000000ULL);
1405 Check(v, 0.0036621093750000000000L, intPart, 0xF0000000000000ULL);
1406 Check(v, 0.0585937500000000000000L, intPart, 0xF00000000000000ULL);
1407 std::cout << std::endl;
1408 Check(v, 0.4999999999999999991326L, intPart, 0x7FFFFFFFFFFFFFF0ULL);
1409 Check(v, 0.4999999999999999991868L, intPart, 0x7FFFFFFFFFFFFFF1ULL);
1410 Check(v, 0.4999999999999999992411L, intPart, 0x7FFFFFFFFFFFFFF2ULL);
1411 Check(v, 0.4999999999999999992953L, intPart, 0x7FFFFFFFFFFFFFF3ULL);
1412 Check(v, 0.4999999999999999993495L, intPart, 0x7FFFFFFFFFFFFFF4ULL);
1413 Check(v, 0.4999999999999999994037L, intPart, 0x7FFFFFFFFFFFFFF5ULL);
1414 Check(v, 0.4999999999999999994579L, intPart, 0x7FFFFFFFFFFFFFF6ULL);
1415 Check(v, 0.4999999999999999995121L, intPart, 0x7FFFFFFFFFFFFFF7ULL);
1416 Check(v, 0.4999999999999999995663L, intPart, 0x7FFFFFFFFFFFFFF8ULL);
1417 Check(v, 0.4999999999999999996205L, intPart, 0x7FFFFFFFFFFFFFF9ULL);
1418 Check(v, 0.4999999999999999996747L, intPart, 0x7FFFFFFFFFFFFFFAULL);
1419 Check(v, 0.4999999999999999997289L, intPart, 0x7FFFFFFFFFFFFFFBULL);
1420 Check(v, 0.4999999999999999997832L, intPart, 0x7FFFFFFFFFFFFFFCULL);
1421 Check(v, 0.4999999999999999998374L, intPart, 0x7FFFFFFFFFFFFFFDULL);
1422 Check(v, 0.4999999999999999998916L, intPart, 0x7FFFFFFFFFFFFFFEULL);
1423 Check(v, 0.4999999999999999999458L, intPart, 0x7FFFFFFFFFFFFFFFULL);
1424 Check(v, 0.5000000000000000000000L, intPart, 0x8000000000000000ULL);
1425 Check(v, 0.5000000000000000000542L, intPart, 0x8000000000000001ULL);
1426 Check(v, 0.5000000000000000001084L, intPart, 0x8000000000000002ULL);
1427 Check(v, 0.5000000000000000001626L, intPart, 0x8000000000000003ULL);
1428 Check(v, 0.5000000000000000002168L, intPart, 0x8000000000000004ULL);
1429 Check(v, 0.5000000000000000002711L, intPart, 0x8000000000000005ULL);
1430 Check(v, 0.5000000000000000003253L, intPart, 0x8000000000000006ULL);
1431 Check(v, 0.5000000000000000003795L, intPart, 0x8000000000000007ULL);
1432 Check(v, 0.5000000000000000004337L, intPart, 0x8000000000000008ULL);
1433 Check(v, 0.5000000000000000004879L, intPart, 0x8000000000000009ULL);
1434 Check(v, 0.5000000000000000005421L, intPart, 0x800000000000000AULL);
1435 Check(v, 0.5000000000000000005963L, intPart, 0x800000000000000BULL);
1436 Check(v, 0.5000000000000000006505L, intPart, 0x800000000000000CULL);
1437 Check(v, 0.5000000000000000007047L, intPart, 0x800000000000000DULL);
1438 Check(v, 0.5000000000000000007589L, intPart, 0x800000000000000EULL);
1439 Check(v, 0.5000000000000000008132L, intPart, 0x800000000000000FULL);
1440 std::cout << std::endl;
1441 Check(v, 0.9375000000000000000000L, intPart, 0xF000000000000000ULL);
1442 Check(v, 0.9960937500000000000000L, intPart, 0xFF00000000000000ULL);
1443 Check(v, 0.9997558593750000000000L, intPart, 0xFFF0000000000000ULL);
1444 Check(v, 0.9999847412109375000000L, intPart, 0xFFFF000000000000ULL);
1445 Check(v, 0.9999990463256835937500L, intPart, 0xFFFFF00000000000ULL);
1446 Check(v, 0.9999999403953552246094L, intPart, 0xFFFFFF0000000000ULL);
1447 Check(v, 0.9999999962747097015381L, intPart, 0xFFFFFFF000000000ULL);
1448 Check(v, 0.9999999997671693563461L, intPart, 0xFFFFFFFF00000000ULL);
1449 Check(v, 0.9999999999854480847716L, intPart, 0xFFFFFFFFF0000000ULL);
1450 Check(v, 0.9999999999990905052982L, intPart, 0xFFFFFFFFFF000000ULL);
1451 Check(v, 0.9999999999999431565811L, intPart, 0xFFFFFFFFFFF00000ULL);
1452 Check(v, 0.9999999999999964472863L, intPart, 0xFFFFFFFFFFFF0000ULL);
1453 Check(v, 0.9999999999999997779554L, intPart, 0xFFFFFFFFFFFFF000ULL);
1454 Check(v, 0.9999999999999999861222L, intPart, 0xFFFFFFFFFFFFFF00ULL);
1455 Check(v, 0.9999999999999999991326L, intPart, 0xFFFFFFFFFFFFFFF0ULL);
1456 Check(v, 0.9999999999999999991868L, intPart, 0xFFFFFFFFFFFFFFF1ULL);
1457 Check(v, 0.9999999999999999992411L, intPart, 0xFFFFFFFFFFFFFFF2ULL);
1458 Check(v, 0.9999999999999999992943L, intPart, 0xFFFFFFFFFFFFFFF3ULL);
1459 Check(v, 0.9999999999999999993495L, intPart, 0xFFFFFFFFFFFFFFF4ULL);
1460 Check(v, 0.9999999999999999994037L, intPart, 0xFFFFFFFFFFFFFFF5ULL);
1461 Check(v, 0.9999999999999999994579L, intPart, 0xFFFFFFFFFFFFFFF6ULL);
1462 Check(v, 0.9999999999999999995121L, intPart, 0xFFFFFFFFFFFFFFF7ULL);
1463 Check(v, 0.9999999999999999995663L, intPart, 0xFFFFFFFFFFFFFFF8ULL);
1464 Check(v, 0.9999999999999999996205L, intPart, 0xFFFFFFFFFFFFFFF9ULL);
1465 Check(v, 0.9999999999999999996747L, intPart, 0xFFFFFFFFFFFFFFFAULL);
1466 Check(v, 0.9999999999999999997289L, intPart, 0xFFFFFFFFFFFFFFFBULL);
1467 Check(v, 0.9999999999999999997832L, intPart, 0xFFFFFFFFFFFFFFFCULL);
1468 Check(v, 0.9999999999999999998374L, intPart, 0xFFFFFFFFFFFFFFFDULL);
1469 Check(v, 0.9999999999999999998916L, intPart, 0xFFFFFFFFFFFFFFFEULL);
1470 Check(v, 0.9999999999999999999458L, intPart, 0xFFFFFFFFFFFFFFFFULL);
1473 <<
"integer:" << std::setw(4) << intPart <<
": deltas:" << std::setw(4)
1484 std::cout << std::endl;
1488 std::ios_base::fmtflags ff = std::cout.flags();
1491 <<
"FLT_RADIX: " << FLT_RADIX
1492 <<
"\n LDBL_MANT_DIG: " << LDBL_MANT_DIG
1495 <<
MIN_LOW <<
")" << std::defaultfloat
1498 std::cout << std::scientific << std::setprecision(21);
1510 std::cout.flags(ff);
1522 void DoRun()
override;
1526 :
TestCase(
"Print the implementation")
1533 std::cout << std::endl;
1536 std::cout <<
"int64x64_t::implementation: ";
1540 std::cout <<
"int128_impl";
1543 std::cout <<
"cairo_impl";
1546 std::cout <<
"ld_impl";
1549 std::cout <<
"unknown!";
1551 std::cout << std::endl;
1553#if defined(INT64X64_USE_CAIRO) && !defined(PYTHON_SCAN)
1554 std::cout <<
"cairo_impl64: " <<
cairo_impl64 << std::endl;
1555 std::cout <<
"cairo_impl128: " <<
cairo_impl128 << std::endl;
1560 std::cout <<
"Running with 64-bit long doubles" << std::endl;
const char * cairo_impl64
const char * cairo_impl128
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase * GetParent() const
Get the parent of this TestCase.
std::string GetName() const
static constexpr auto UNIT
Test: basic arithmetic operations.
void DoRun() override
Implementation to actually run this TestCase.
Int64x64ArithmeticTestCase()
void Check(const int test, const int64x64_t value, const int64x64_t expect, const int64x64_t tolerance=int64x64_t(0, 0))
Check the int64x64 for correctness.
void Check(const uint64_t low, const std::string &value, const int64_t tolerance=0)
Check the int64x64 for correctness.
Int64x64Bug1786TestCase()
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
void Check(const double result, const double expect, const std::string &msg)
Check the int64x64 for correctness.
void Check(const double result, const double expect, const std::string &msg)
Check the int64x64 for correctness.
void DoRun() override
Implementation to actually run this TestCase.
Test: basic compare operations.
void DoRun() override
Implementation to actually run this TestCase.
void Check(const bool result, const bool expect, const std::string &msg)
Check the int64x64 for correctness.
Int64x64CompareTestCase()
Test: construct from floating point.
static constexpr long double MIN_LOW
The smallest low word we expect to get from a conversion.
static constexpr int MISS_MANT_DIG
Compute a multiplier to match the mantissa size on this platform.
void DoRun() override
Implementation to actually run this TestCase.
void Check(const int64_t intPart)
Check the int64x64 for correctness.
int m_deltaCount
The number of times a delta was recorded.
long double m_last
The last value tested.
static const long double MIN_MANT
Smallest mantissa we expect to convert to a non-zero low word.
int64x64_t m_deltaMax
The maximum observed difference between expected and computed values.
Test: manipulate the high and low part of every number.
void DoRun() override
Implementation to actually run this TestCase.
void Check(const int64_t hi, const uint64_t lo)
Check the high and low parts for correctness.
Test: print the implementation.
void DoRun() override
Implementation to actually run this TestCase.
Test: check GetInt and Round.
void Check(const int64x64_t value, const int64_t expectInt, const int64_t expectRnd)
Check the int64x64 value for correctness.
Int64x64IntRoundTestCase()
void DoRun() override
Implementation to actually run this TestCase.
Test: Invert and MulByInvert.
void CheckCase(const uint64_t factor, const int64x64_t result, const int64x64_t expect, const std::string &msg, const double tolerance=0)
Check the int64x64 for correctness.
void DoRun() override
Implementation to actually run this TestCase.
void Check(const int64_t factor)
Check the int64x64 for correctness.
Pretty printer for test cases.
int64x64_t m_value
The int64x64_t value.
friend std::ostream & operator<<(std::ostream &os, const Printer &p)
Output streamer, the main reason for this class.
bool m_haveInt
Do we have a full int64x64_t value?
int64_t m_high
The high (integer) word.
Printer(const int64x64_t value)
Construct from an int64x64_t Q64.64 value.
Printer(const int64_t high, const uint64_t low)
Construct from high and low words of Q64.64 representation.
uint64_t m_low
The low (fractional) word.
High precision numerical type, implementing Q64.64 fixed precision.
@ int128_impl
Native int128_t implementation.
@ ld_impl
long double implementation.
@ cairo_impl
Cairo wideint implementation.
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
static enum impl_type implementation
Type tag for this implementation.
double GetDouble() const
Get this value as a double.
static int64x64_t Invert(const uint64_t v)
Compute the inverse of an integer value.
int64x64_t Abs(const int64x64_t &value)
Absolute value.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
#define HP_MAX_64
Floating point value of HP_MASK_LO + 1.
#define RUNNING_WITH_LIMITED_PRECISION
Checks if running on Valgrind, which assumes long doubles are 64-bit doubles.
std::ostream & operator<<(std::ostream &os, const Printer &p)
static Int64x64TestSuite g_int64x64TestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
-ns3 Test suite for the ns3 wrapper script
-ray-to-three-gpp-ch-calibration