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;
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;
456 void Check(
const int test,
463 :
TestCase(
"Basic arithmetic operations")
473 bool pass =
Abs(value - expect) <= tolerance;
475 std::cout <<
GetParent()->
GetName() <<
" Arithmetic: " << (pass ?
"pass " :
"FAIL ") << test
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));
591 void DoRun()
override;
598 void Check(
const double result,
const double expect,
const std::string& msg);
609 bool pass = result == expect;
611 std::cout <<
GetParent()->
GetName() <<
" Bug 455: " << (pass ?
"pass " :
"FAIL ")
612 <<
"res: " << result <<
" exp: " << expect <<
": " << msg << std::endl;
620 std::cout << std::endl;
633 Check(a.
GetDouble(), -2.5,
"Test sign, first operation negative");
655 void DoRun()
override;
662 void Check(
const double result,
const double expect,
const std::string& msg);
673 bool pass = result == expect;
675 std::cout <<
GetParent()->
GetName() <<
" Bug 863: " << (pass ?
"pass " :
"FAIL ")
676 <<
"res: " << result <<
" exp: " << expect <<
": " << msg << std::endl;
684 std::cout << std::endl;
696 Check(a.
GetDouble(), -0.5,
"Check that we actually convert doubles correctly");
721 void DoRun()
override;
728 void Check(
const uint64_t low,
const std::string& value,
const int64_t tolerance = 0);
732 :
TestCase(
"Test case for bug 1786")
738 const std::string& str,
739 const int64_t tolerance )
742 std::ostringstream oss;
743 oss << std::scientific << std::setprecision(22) << value;
747 bool pass = oss.str() == str;
749 std::cout <<
GetParent()->
GetName() <<
" Bug 1786: " << (pass ?
"pass " :
"FAIL ")
750 <<
" 0x" << std::hex << std::setw(16) << low << std::dec <<
" = " << oss.str();
753 std::cout <<
", expected " << str;
755 std::cout << std::endl;
765 <<
" 0x" << std::hex << std::setw(16) << low << std::dec <<
" = " << oss.str()
766 <<
", expected " << str << std::endl;
773 std::cout << std::endl;
776 int64_t tolerance = 0;
790 Check( 1ULL,
"+0.0000000000000000000542");
791 Check( 2ULL,
"+0.0000000000000000001084");
792 Check( 3ULL,
"+0.0000000000000000001626");
793 Check( 4ULL,
"+0.0000000000000000002168");
794 Check( 5ULL,
"+0.0000000000000000002710");
795 Check( 6ULL,
"+0.0000000000000000003253");
796 Check( 7ULL,
"+0.0000000000000000003795");
797 Check( 8ULL,
"+0.0000000000000000004337");
798 Check( 9ULL,
"+0.0000000000000000004879");
799 Check( 0xAULL,
"+0.0000000000000000005421");
800 Check( 0xFULL,
"+0.0000000000000000008132");
801 Check( 0xF0ULL,
"+0.0000000000000000130104");
802 Check( 0xF00ULL,
"+0.0000000000000002081668");
803 Check( 0xF000ULL,
"+0.0000000000000033306691");
804 Check( 0xF0000ULL,
"+0.0000000000000532907052");
805 Check( 0xF00000ULL,
"+0.0000000000008526512829");
806 Check( 0xF000000ULL,
"+0.0000000000136424205266");
807 Check( 0xF0000000ULL,
"+0.0000000002182787284255");
808 Check( 0xF00000000ULL,
"+0.0000000034924596548080");
809 Check( 0xF000000000ULL,
"+0.0000000558793544769287");
810 Check( 0xF0000000000ULL,
"+0.0000008940696716308594");
811 Check( 0xF00000000000ULL,
"+0.0000143051147460937500");
812 Check( 0xF000000000000ULL,
"+0.0002288818359375000000");
813 Check( 0xF0000000000000ULL,
"+0.0036621093750000000000");
814 Check( 0xF00000000000000ULL,
"+0.0585937500000000000000");
815 std::cout << std::endl;
816 Check(0x7FFFFFFFFFFFFFFDULL,
"+0.4999999999999999998374", tolerance);
817 Check(0x7FFFFFFFFFFFFFFEULL,
"+0.4999999999999999998916", tolerance);
818 Check(0x7FFFFFFFFFFFFFFFULL,
"+0.4999999999999999999458", tolerance);
819 Check(0x8000000000000000ULL,
"+0.5000000000000000000000");
820 Check(0x8000000000000001ULL,
"+0.5000000000000000000542", tolerance);
821 Check(0x8000000000000002ULL,
"+0.5000000000000000001084", tolerance);
822 Check(0x8000000000000003ULL,
"+0.5000000000000000001626", tolerance);
823 std::cout << std::endl;
824 Check(0xF000000000000000ULL,
"+0.9375000000000000000000");
825 Check(0xFF00000000000000ULL,
"+0.9960937500000000000000");
826 Check(0xFFF0000000000000ULL,
"+0.9997558593750000000000");
827 Check(0xFFFF000000000000ULL,
"+0.9999847412109375000000");
828 Check(0xFFFFF00000000000ULL,
"+0.9999990463256835937500");
829 Check(0xFFFFFF0000000000ULL,
"+0.9999999403953552246094");
830 Check(0xFFFFFFF000000000ULL,
"+0.9999999962747097015381");
831 Check(0xFFFFFFFF00000000ULL,
"+0.9999999997671693563461");
832 Check(0xFFFFFFFFF0000000ULL,
"+0.9999999999854480847716");
833 Check(0xFFFFFFFFFF000000ULL,
"+0.9999999999990905052982");
834 Check(0xFFFFFFFFFFF00000ULL,
"+0.9999999999999431565811");
835 Check(0xFFFFFFFFFFFF0000ULL,
"+0.9999999999999964472863");
836 Check(0xFFFFFFFFFFFFF000ULL,
"+0.9999999999999997779554");
837 Check(0xFFFFFFFFFFFFFF00ULL,
"+0.9999999999999999861222");
838 Check(0xFFFFFFFFFFFFFFF0ULL,
"+0.9999999999999999991326");
839 Check(0xFFFFFFFFFFFFFFF5ULL,
"+0.9999999999999999994037", tolerance);
840 Check(0xFFFFFFFFFFFFFFF6ULL,
"+0.9999999999999999994579", tolerance);
841 Check(0xFFFFFFFFFFFFFFF7ULL,
"+0.9999999999999999995121", tolerance);
842 Check(0xFFFFFFFFFFFFFFF8ULL,
"+0.9999999999999999995663", tolerance);
843 Check(0xFFFFFFFFFFFFFFF9ULL,
"+0.9999999999999999996205", tolerance);
844 Check(0xFFFFFFFFFFFFFFFAULL,
"+0.9999999999999999996747", tolerance);
845 Check(0xFFFFFFFFFFFFFFFBULL,
"+0.9999999999999999997289", tolerance);
846 Check(0xFFFFFFFFFFFFFFFCULL,
"+0.9999999999999999997832", tolerance);
847 Check(0xFFFFFFFFFFFFFFFDULL,
"+0.9999999999999999998374", tolerance);
848 Check(0xFFFFFFFFFFFFFFFEULL,
"+0.9999999999999999998916", tolerance);
849 Check(0xFFFFFFFFFFFFFFFFULL,
"+0.9999999999999999999458", tolerance);
863 void DoRun()
override;
871 void Check(
const bool result,
const bool expect,
const std::string& msg);
875 :
TestCase(
"Basic compare operations")
882 bool pass = result == expect;
884 std::cout <<
GetParent()->
GetName() <<
" Compare: " << (pass ?
"pass " :
"FAIL ") << msg
893 std::cout << std::endl;
908 Check(zerof == zerof,
true,
"equality, zero");
909 Check(onef == onef,
true,
"equality, positive");
910 Check(mtwof == mtwof,
true,
"equality, negative");
911 Check(
zero == one,
false,
"equality false, zero");
912 Check(one ==
two,
false,
"equality false, unsigned");
913 Check(one == mone,
false,
"equality false, signed");
914 Check(onef == one,
false,
"equality false, fraction");
915 std::cout << std::endl;
917 Check(zerof != zerof,
false,
"inequality, zero");
918 Check(onef != onef,
false,
"inequality, positive");
919 Check(mtwof != mtwof,
false,
"inequality, negative");
920 Check(
zero != one,
true,
"inequality true, zero");
921 Check(one !=
two,
true,
"inequality true, unsigned");
922 Check(one != mone,
true,
"inequality true, signed");
923 Check(onef != one,
true,
"inequality true, fraction");
924 std::cout << std::endl;
926 Check(zerof < onef,
true,
"less, zerof");
928 Check(one < onef,
true,
"less, positive");
929 Check(monef < mone,
true,
"less, negative");
930 Check(onef < one,
false,
"less, false, positive");
931 Check(mtwo < mtwof,
false,
"less, false, negative");
932 std::cout << std::endl;
934 Check(zerof <= zerof,
true,
"less equal, equal, zerof");
935 Check(
zero <= zerof,
true,
"less equal, less, zero");
936 Check(onef <= onef,
true,
"less equal, equal, positive");
937 Check(monef <= mone,
true,
"less equal, less, negative");
938 Check(onef <= one,
false,
"less equal, false, positive");
939 Check(mtwo <= mtwof,
false,
"less equal, false, negative");
940 std::cout << std::endl;
942 Check(onef > zerof,
true,
"greater, zerof");
943 Check(zerof >
zero,
true,
"greater, zero");
944 Check(onef > one,
true,
"greater, positive");
945 Check(mone > monef,
true,
"greater, negative");
946 Check(one > onef,
false,
"greater, false, positive");
947 Check(mtwof > mtwo,
false,
"greater, false, negative");
948 std::cout << std::endl;
950 Check(zerof >= zerof,
true,
"greater equal, equal, zerof");
951 Check(zerof >=
zero,
true,
"greater equal, greater, zero");
952 Check(onef >= onef,
true,
"greater equal, equal, positive");
953 Check(mone >= monef,
true,
"greater equal, greater, negative");
954 Check(one >= onef,
false,
"greater equal, false, positive");
955 Check(mtwof >= mtwo,
false,
"greater equal, false, negative");
956 std::cout << std::endl;
958 Check(
zero ==
false,
true,
"zero == false");
959 Check(one ==
true,
true,
"one == true");
960 Check(zerof !=
false,
true,
"zerof != false");
961 Check((!
zero) ==
true,
true,
"!zero == true");
962 Check((!zerof) ==
false,
true,
"!zerof == false");
963 Check((!one) ==
false,
true,
"!one == false");
964 Check((+onef) == onef,
true,
"unary positive");
965 Check((-onef) == monef,
true,
"unary negative");
978 void DoRun()
override;
983 void Check(
const int64_t factor);
995 const std::string& msg,
996 const double tolerance = 0);
1000 :
TestCase(
"Invert and MulByInvert")
1008 const std::string& msg,
1009 const double tolerance )
1011 bool pass =
Abs(result - expect) <= tolerance;
1017 std::cout <<
"pass: " << factor <<
": ";
1021 std::cout <<
"FAIL: " << factor <<
": "
1022 <<
"(res: " << result <<
" exp: " << expect <<
" tol: " << tolerance <<
") ";
1024 std::cout << msg << std::endl;
1038 double tolerance = 0;
1042 tolerance = 0.000000000000000001L;
1046 CheckCase(factor, b, one,
"x * x^-1 == 1", tolerance);
1050 CheckCase(factor, c, factorI,
"1 * x^-1 == 1 / x");
1058 CheckCase(factor, e, -one,
"-x * x^-1 == -1", tolerance);
1064 std::cout << std::endl;
1083 Check(10000000000LL);
1084 Check(100000000000LL);
1085 Check(1000000000000LL);
1086 Check(10000000000000LL);
1087 Check(100000000000000LL);
1088 Check(1000000000000000LL);
1100 void DoRun()
override;
1106 void Check(
const int64_t intPart);
1114 void Check(
const long double dec,
1115 const long double frac,
1116 const int64_t intPart,
1173 std::round(1e22 / std::pow(2.0L,
std::min(64, LDBL_MANT_DIG))) / 1e22;
1176 :
TestCase(
"Construct from floating point."),
1185 const long double frac,
1186 const int64_t intPart,
1190 long double value = dec + frac;
1250 const bool skip = (frac && (value ==
m_last));
1263 long double margin = 0;
1283 const bool pass =
delta <= tolerance;
1288 std::ios_base::fmtflags ff = std::cout.flags();
1289 std::cout << std::fixed << std::setprecision(22);
1292 <<
" Double: " << (skip ?
"skip " : (pass ?
"pass " :
"FAIL ")) << std::showpos
1293 << value <<
" == " <<
Printer(result) << (under ?
" (underflow)" :
"") << std::endl;
1298 std::cout <<
GetParent()->
GetName() << std::left << std::setw(43) <<
" expected"
1299 << std::right <<
Printer(expect) << std::endl;
1301 if (
delta == tolerance)
1305 <<
" delta = tolerance" << std::right <<
Printer(
delta) << std::endl;
1310 std::cout <<
GetParent()->
GetName() << std::left << std::setw(43) <<
" delta"
1313 <<
" tolerance" << std::right <<
Printer(tolerance)
1314 <<
" eps: " <<
epsilon <<
", margin: " << margin << std::endl;
1328 std::cout.flags(ff);
1334 std::cout << std::endl;
1336 <<
"integer: " << intPart << std::endl;
1346 long double v = intPart;
1348 Check(v, 0.0L, intPart, 0x0ULL);
1349 Check(v, 0.0000000000000000000542L, intPart, 0x1ULL);
1350 Check(v, 0.0000000000000000001084L, intPart, 0x2ULL);
1351 Check(v, 0.0000000000000000001626L, intPart, 0x3ULL);
1352 Check(v, 0.0000000000000000002168L, intPart, 0x4ULL);
1353 Check(v, 0.0000000000000000002711L, intPart, 0x5ULL);
1354 Check(v, 0.0000000000000000003253L, intPart, 0x6ULL);
1355 Check(v, 0.0000000000000000003795L, intPart, 0x7ULL);
1356 Check(v, 0.0000000000000000004337L, intPart, 0x8ULL);
1357 Check(v, 0.0000000000000000004879L, intPart, 0x9ULL);
1358 Check(v, 0.0000000000000000005421L, intPart, 0xAULL);
1359 Check(v, 0.0000000000000000005963L, intPart, 0xBULL);
1360 Check(v, 0.0000000000000000006505L, intPart, 0xCULL);
1361 Check(v, 0.0000000000000000007047L, intPart, 0xDULL);
1362 Check(v, 0.0000000000000000007589L, intPart, 0xEULL);
1363 Check(v, 0.0000000000000000008132L, intPart, 0xFULL);
1364 Check(v, 0.0000000000000000130104L, intPart, 0xF0ULL);
1365 Check(v, 0.0000000000000002081668L, intPart, 0xF00ULL);
1366 Check(v, 0.0000000000000033306691L, intPart, 0xF000ULL);
1367 Check(v, 0.0000000000000532907052L, intPart, 0xF0000ULL);
1368 Check(v, 0.0000000000008526512829L, intPart, 0xF00000ULL);
1369 Check(v, 0.0000000000136424205266L, intPart, 0xF000000ULL);
1370 Check(v, 0.0000000002182787284255L, intPart, 0xF0000000ULL);
1371 Check(v, 0.0000000034924596548080L, intPart, 0xF00000000ULL);
1372 Check(v, 0.0000000558793544769287L, intPart, 0xF000000000ULL);
1373 Check(v, 0.0000008940696716308594L, intPart, 0xF0000000000ULL);
1374 Check(v, 0.0000143051147460937500L, intPart, 0xF00000000000ULL);
1375 Check(v, 0.0002288818359375000000L, intPart, 0xF000000000000ULL);
1376 Check(v, 0.0036621093750000000000L, intPart, 0xF0000000000000ULL);
1377 Check(v, 0.0585937500000000000000L, intPart, 0xF00000000000000ULL);
1378 std::cout << std::endl;
1379 Check(v, 0.4999999999999999991326L, intPart, 0x7FFFFFFFFFFFFFF0ULL);
1380 Check(v, 0.4999999999999999991868L, intPart, 0x7FFFFFFFFFFFFFF1ULL);
1381 Check(v, 0.4999999999999999992411L, intPart, 0x7FFFFFFFFFFFFFF2ULL);
1382 Check(v, 0.4999999999999999992953L, intPart, 0x7FFFFFFFFFFFFFF3ULL);
1383 Check(v, 0.4999999999999999993495L, intPart, 0x7FFFFFFFFFFFFFF4ULL);
1384 Check(v, 0.4999999999999999994037L, intPart, 0x7FFFFFFFFFFFFFF5ULL);
1385 Check(v, 0.4999999999999999994579L, intPart, 0x7FFFFFFFFFFFFFF6ULL);
1386 Check(v, 0.4999999999999999995121L, intPart, 0x7FFFFFFFFFFFFFF7ULL);
1387 Check(v, 0.4999999999999999995663L, intPart, 0x7FFFFFFFFFFFFFF8ULL);
1388 Check(v, 0.4999999999999999996205L, intPart, 0x7FFFFFFFFFFFFFF9ULL);
1389 Check(v, 0.4999999999999999996747L, intPart, 0x7FFFFFFFFFFFFFFAULL);
1390 Check(v, 0.4999999999999999997289L, intPart, 0x7FFFFFFFFFFFFFFBULL);
1391 Check(v, 0.4999999999999999997832L, intPart, 0x7FFFFFFFFFFFFFFCULL);
1392 Check(v, 0.4999999999999999998374L, intPart, 0x7FFFFFFFFFFFFFFDULL);
1393 Check(v, 0.4999999999999999998916L, intPart, 0x7FFFFFFFFFFFFFFEULL);
1394 Check(v, 0.4999999999999999999458L, intPart, 0x7FFFFFFFFFFFFFFFULL);
1395 Check(v, 0.5000000000000000000000L, intPart, 0x8000000000000000ULL);
1396 Check(v, 0.5000000000000000000542L, intPart, 0x8000000000000001ULL);
1397 Check(v, 0.5000000000000000001084L, intPart, 0x8000000000000002ULL);
1398 Check(v, 0.5000000000000000001626L, intPart, 0x8000000000000003ULL);
1399 Check(v, 0.5000000000000000002168L, intPart, 0x8000000000000004ULL);
1400 Check(v, 0.5000000000000000002711L, intPart, 0x8000000000000005ULL);
1401 Check(v, 0.5000000000000000003253L, intPart, 0x8000000000000006ULL);
1402 Check(v, 0.5000000000000000003795L, intPart, 0x8000000000000007ULL);
1403 Check(v, 0.5000000000000000004337L, intPart, 0x8000000000000008ULL);
1404 Check(v, 0.5000000000000000004879L, intPart, 0x8000000000000009ULL);
1405 Check(v, 0.5000000000000000005421L, intPart, 0x800000000000000AULL);
1406 Check(v, 0.5000000000000000005963L, intPart, 0x800000000000000BULL);
1407 Check(v, 0.5000000000000000006505L, intPart, 0x800000000000000CULL);
1408 Check(v, 0.5000000000000000007047L, intPart, 0x800000000000000DULL);
1409 Check(v, 0.5000000000000000007589L, intPart, 0x800000000000000EULL);
1410 Check(v, 0.5000000000000000008132L, intPart, 0x800000000000000FULL);
1411 std::cout << std::endl;
1412 Check(v, 0.9375000000000000000000L, intPart, 0xF000000000000000ULL);
1413 Check(v, 0.9960937500000000000000L, intPart, 0xFF00000000000000ULL);
1414 Check(v, 0.9997558593750000000000L, intPart, 0xFFF0000000000000ULL);
1415 Check(v, 0.9999847412109375000000L, intPart, 0xFFFF000000000000ULL);
1416 Check(v, 0.9999990463256835937500L, intPart, 0xFFFFF00000000000ULL);
1417 Check(v, 0.9999999403953552246094L, intPart, 0xFFFFFF0000000000ULL);
1418 Check(v, 0.9999999962747097015381L, intPart, 0xFFFFFFF000000000ULL);
1419 Check(v, 0.9999999997671693563461L, intPart, 0xFFFFFFFF00000000ULL);
1420 Check(v, 0.9999999999854480847716L, intPart, 0xFFFFFFFFF0000000ULL);
1421 Check(v, 0.9999999999990905052982L, intPart, 0xFFFFFFFFFF000000ULL);
1422 Check(v, 0.9999999999999431565811L, intPart, 0xFFFFFFFFFFF00000ULL);
1423 Check(v, 0.9999999999999964472863L, intPart, 0xFFFFFFFFFFFF0000ULL);
1424 Check(v, 0.9999999999999997779554L, intPart, 0xFFFFFFFFFFFFF000ULL);
1425 Check(v, 0.9999999999999999861222L, intPart, 0xFFFFFFFFFFFFFF00ULL);
1426 Check(v, 0.9999999999999999991326L, intPart, 0xFFFFFFFFFFFFFFF0ULL);
1427 Check(v, 0.9999999999999999991868L, intPart, 0xFFFFFFFFFFFFFFF1ULL);
1428 Check(v, 0.9999999999999999992411L, intPart, 0xFFFFFFFFFFFFFFF2ULL);
1429 Check(v, 0.9999999999999999992943L, intPart, 0xFFFFFFFFFFFFFFF3ULL);
1430 Check(v, 0.9999999999999999993495L, intPart, 0xFFFFFFFFFFFFFFF4ULL);
1431 Check(v, 0.9999999999999999994037L, intPart, 0xFFFFFFFFFFFFFFF5ULL);
1432 Check(v, 0.9999999999999999994579L, intPart, 0xFFFFFFFFFFFFFFF6ULL);
1433 Check(v, 0.9999999999999999995121L, intPart, 0xFFFFFFFFFFFFFFF7ULL);
1434 Check(v, 0.9999999999999999995663L, intPart, 0xFFFFFFFFFFFFFFF8ULL);
1435 Check(v, 0.9999999999999999996205L, intPart, 0xFFFFFFFFFFFFFFF9ULL);
1436 Check(v, 0.9999999999999999996747L, intPart, 0xFFFFFFFFFFFFFFFAULL);
1437 Check(v, 0.9999999999999999997289L, intPart, 0xFFFFFFFFFFFFFFFBULL);
1438 Check(v, 0.9999999999999999997832L, intPart, 0xFFFFFFFFFFFFFFFCULL);
1439 Check(v, 0.9999999999999999998374L, intPart, 0xFFFFFFFFFFFFFFFDULL);
1440 Check(v, 0.9999999999999999998916L, intPart, 0xFFFFFFFFFFFFFFFEULL);
1441 Check(v, 0.9999999999999999999458L, intPart, 0xFFFFFFFFFFFFFFFFULL);
1444 <<
"integer:" << std::setw(4) << intPart <<
": deltas:" << std::setw(4)
1455 std::cout << std::endl;
1459 std::ios_base::fmtflags ff = std::cout.flags();
1462 <<
"FLT_RADIX: " << FLT_RADIX
1463 <<
"\n LDBL_MANT_DIG: " << LDBL_MANT_DIG
1466 <<
MIN_LOW <<
")" << std::defaultfloat
1469 std::cout << std::scientific << std::setprecision(21);
1481 std::cout.flags(ff);
1493 void DoRun()
override;
1497 :
TestCase(
"Print the implementation")
1504 std::cout << std::endl;
1507 std::cout <<
"int64x64_t::implementation: ";
1511 std::cout <<
"int128_impl";
1514 std::cout <<
"cairo_impl";
1517 std::cout <<
"ld_impl";
1520 std::cout <<
"unknown!";
1522 std::cout << std::endl;
1524 #if defined(INT64X64_USE_CAIRO) && !defined(PYTHON_SCAN)
1525 std::cout <<
"cairo_impl64: " <<
cairo_impl64 << std::endl;
1526 std::cout <<
"cairo_impl128: " <<
cairo_impl128 << std::endl;
1531 std::cout <<
"Running with 64-bit long doubles" << std::endl;
const char * cairo_impl64
const char * cairo_impl128
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
TestCase * GetParent() const
Get the parent of this TestCase.
std::string GetName() const
@ UNIT
This test suite implements a Unit Test.
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.
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.
friend std::ostream & operator<<(std::ostream &os, const Printer &p)
Output streamer, the main reason for this class.
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 Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
int64x64_t Abs(const int64x64_t &value)
Absolute value.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
#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 We really want:
#define RUNNING_WITH_LIMITED_PRECISION
Checks if running on Valgrind, which assumes long doubles are 64-bit doubles.
static Int64x64TestSuite g_int64x64TestSuite
Static variable for test initialization.
std::ostream & operator<<(std::ostream &os, const Printer &p)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
-ray-to-three-gpp-ch-calibration