20 #include "ns3/int64x64.h"
22 #include "ns3/valgrind.h"
63 Printer (
const int64_t high,
const uint64_t low)
79 m_low (value.GetLow ())
102 os << std::fixed << std::setprecision (22)
107 os << std::hex << std::setfill (
'0')
108 <<
" (0x" << std::setw (16) << p.
m_high
109 <<
" 0x" << std::setw (16) << p.
m_low <<
")"
110 << std::dec << std::setfill (
' ');
123 virtual void DoRun (
void);
129 void Check (
const int64_t hi,
const uint64_t lo);
133 :
TestCase (
"Manipulate the high and low part of every number")
139 uint64_t tolerance = 0;
147 uint64_t vLow = value.GetLow ();
148 bool pass = ( (value.GetHigh () == hi)
149 && ( (
Max (vLow, lo) -
Min (vLow, lo)) <= tolerance)
153 << (pass ?
"pass " :
"FAIL ")
158 "High part does not match for hi:" << hi
161 "Low part does not match for hi: " << hi
168 std::cout << std::endl;
181 Check ( 0, 0xffffffffffffffffULL - low);
185 Check ( 1, 0xffffffffffffffffULL - low);
189 Check (-1, 0xffffffffffffffffULL - low);
202 virtual void DoRun (
void);
210 const int64_t expectInt,
211 const int64_t expectRnd);
215 :
TestCase (
"Check GetInt and Round")
220 const int64_t expectInt,
221 const int64_t expectRnd)
223 int64_t vInt = value.GetInt ();
224 int64_t vRnd = value.Round ();
226 bool pass = (vInt == expectInt) && (vRnd == expectRnd);
228 << (pass ?
"pass " :
"FAIL ")
230 <<
" (int)-> " << std::setw (2) << vInt <<
" (expected: " << std::setw (2) << expectInt
231 <<
"), (rnd)-> " << std::setw (2) << vRnd <<
" (expected " << std::setw (2) << expectRnd
236 "Truncation to int failed");
238 "Rounding to int failed.");
244 std::cout << std::endl;
255 Check (-2.4, -2, -2);
259 Check (-3.6, -3, -4);
262 Check (-4.5, -4, -5);
275 virtual void DoRun (
void);
283 void Check (
const std::string & str,
284 const int64_t hi,
const uint64_t lo,
285 const int64_t tolerance = 0);
288 :
TestCase (
"Parse int64x64_t numbers as strings")
292 const int64_t hi,
const uint64_t lo,
293 const int64_t tolerance )
296 std::istringstream iss;
301 std::string input =
"\"" + str +
"\"";
302 uint64_t vLow = value.GetLow ();
303 bool pass = ( (value.GetHigh () == hi)
304 && (
Max (vLow, lo) -
Min (vLow, lo) <= tolerance)
308 << (pass ?
"pass " :
"FAIL ")
309 << std::left << std::setw (28) << input << std::right
311 <<
" expected: " <<
Printer (hi, lo) <<
" +/- " << tolerance
315 "High parts do not match for input string \""
318 "Low parts do not match for input string \""
324 std::cout << std::endl;
328 int64_t tolerance = 0;
339 Check (
"+1.0", 1, 0);
340 Check (
"001.0", 1, 0);
341 Check (
"+001.0", 1, 0);
342 Check (
"020.0", 20, 0);
343 Check (
"+020.0", 20, 0);
344 Check (
"1.0000000", 1, 0);
345 Check (
"-1.0", -1, 0, tolerance);
346 Check (
"-1.0000", -1, 0, tolerance);
347 Check (
" 1.000000000000000000054", 1, 1, tolerance);
348 Check (
"-1.000000000000000000054", (int64_t)-2, (uint64_t)-1, tolerance);
363 virtual void DoRun (
void);
369 void Check (
const std::string & str,
370 const int64_t tolerance = 0);
373 :
TestCase (
"Roundtrip int64x64_t numbers as strings")
377 const int64_t tolerance )
379 std::stringstream iss (str);
383 std::stringstream oss;
384 oss << std::scientific << std::setprecision (21) << expect;
388 bool pass =
Abs (value - expect) <=
int64x64_t (0, tolerance + 1);
390 std::string input =
"\"" + str +
"\"";
391 std::string output =
"\"" + oss.str () +
"\"";
396 << (pass ?
"pass " :
"FAIL ")
397 <<
" in: " << std::left << std::setw (28) << input
398 <<
" out: " << std::left << std::setw (28) << output
405 << (pass ?
"pass " :
"FAIL ")
406 <<
" in: " << std::left << std::setw (28) << input
407 << std::right <<
Printer (expect)
410 << std::setw (19) <<
" "
411 <<
" out: " << std::left << std::setw (28) << output
412 << std::right <<
Printer (value)
417 "Converted string does not match expected string");
423 std::cout << std::endl;
427 int64_t tolerance = 0;
434 Check (
"+1.000000000000000000000");
435 Check (
"+20.000000000000000000000");
436 Check (
"+0.000000000000000000000", tolerance);
437 Check (
"-1.000000000000000000000", tolerance);
438 Check (
"+1.084467440737095516158", tolerance);
439 Check (
"-2.084467440737095516158", tolerance);
440 Check (
"+3.184467440737095516179", tolerance);
441 Check (
"-4.184467440737095516179", tolerance);
454 virtual void DoRun (
void);
462 void Check (
const int test,
468 :
TestCase (
"Basic arithmetic operations")
476 bool pass =
Abs (value - expect) <= tolerance;
479 << (pass ?
"pass " :
"FAIL ")
480 << test <<
": " << value <<
" == " << expect
481 <<
" (+/- " << tolerance <<
")"
485 "Arithmetic failure in test case " << test);
497 std::cout << std::endl;
504 Check ( 3, one - two, -one );
505 Check ( 4, one - (-one ), two );
506 Check ( 5, (-one ) - (-two ), one );
507 Check ( 6, (-one ) - two, -thre );
511 Check ( 9, one + one, two );
512 Check (10, one + two, thre );
514 Check (12, (-one ) + (-two ), -thre );
515 Check (13, (-one ) + two, one );
520 Check (17, one * one, one );
521 Check (18, one * (-one ), -one );
522 Check (19, (-one ) * (-one ), one );
524 Check (20, (two * thre ) / thre, two );
529 Check (21, frac, 0.75);
530 Check (22, fplf2, 1.3125);
537 Check (23, zerof, frac);
541 Check (25, zerof - onef, -one );
543 Check (27, onef - twof, -one );
544 Check (28, onef - (-onef), twof + frac );
545 Check (29, (-onef) - (-twof), one );
546 Check (30, (-onef) - twof, -thref - frac );
548 Check (31, zerof + zerof, zerof + frac );
549 Check (32, zerof + onef, onef + frac );
550 Check (33, onef + onef, twof + frac );
551 Check (34, onef + twof, thref + frac );
553 Check (36, (-onef) + (-twof), -thref - frac );
554 Check (37, (-onef) + twof, one );
556 Check (38, zerof * zerof, frac * frac );
558 Check (40, zerof * one, frac );
560 Check (41, zerof * onef, fplf2 );
561 Check (42, zerof * (-onef), -fplf2 );
562 Check (43, onef * onef, onef + fplf2 );
563 Check (44, onef * (-onef), -onef - fplf2 );
564 Check (45, (-onef) * (-onef), onef + fplf2 );
568 Check (46, (two * thre ) / thre, two );
569 Check (47, (twof * thref) / thref, twof );
572 Check (48, (two / thre) * thre, two, 2 * tol1 );
573 Check (49, (twof / thref) * thref, twof, 3 * tol1 );
579 int64x64_t (1999999999, 0xfffffffffffffffeULL));
600 virtual void DoRun (
void);
607 void Check (
const double result,
const double expect,
608 const std::string & msg);
612 :
TestCase (
"Test case for bug 455")
616 const std::string & msg)
618 bool pass =
result == expect;
621 << (pass ?
"pass " :
"FAIL ")
623 <<
" exp: " << expect
633 std::cout << std::endl;
647 Check (a.
GetDouble (), -2.5,
"Test sign, first operation negative");
671 virtual void DoRun (
void);
678 void Check (
const double result,
const double expect,
679 const std::string & msg);
683 :
TestCase (
"Test case for bug 863")
687 const std::string & msg)
689 bool pass =
result == expect;
692 << (pass ?
"pass " :
"FAIL ")
694 <<
" exp: " << expect
704 std::cout << std::endl;
717 Check (a.
GetDouble (), -0.5,
"Check that we actually convert doubles correctly");
743 virtual void DoRun (
void);
750 void Check (
const uint64_t low,
const std::string & value,
751 const int64_t tolerance = 0);
755 :
TestCase (
"Test case for bug 1786")
759 const std::string & str,
760 const int64_t tolerance )
763 std::ostringstream oss;
764 oss << std::scientific << std::setprecision (22) << value;
768 bool pass = oss.str () == str;
771 << (pass ?
"pass " :
"FAIL ")
772 <<
" 0x" << std::hex << std::setw (16) << low << std::dec
773 <<
" = " << oss.str ();
776 std::cout <<
", expected " << str;
778 std::cout << std::endl;
781 "Fraction string not correct");
789 <<
" 0x" << std::hex << std::setw (16) << low << std::dec
790 <<
" = " << oss.str ()
791 <<
", expected " << str
799 std::cout << std::endl;
803 int64_t tolerance = 0;
814 Check ( 1ULL,
"+0.0000000000000000000542");
815 Check ( 2ULL,
"+0.0000000000000000001084");
816 Check ( 3ULL,
"+0.0000000000000000001626");
817 Check ( 4ULL,
"+0.0000000000000000002168");
818 Check ( 5ULL,
"+0.0000000000000000002710");
819 Check ( 6ULL,
"+0.0000000000000000003253");
820 Check ( 7ULL,
"+0.0000000000000000003795");
821 Check ( 8ULL,
"+0.0000000000000000004337");
822 Check ( 9ULL,
"+0.0000000000000000004879");
823 Check ( 0xAULL,
"+0.0000000000000000005421");
824 Check ( 0xFULL,
"+0.0000000000000000008132");
825 Check ( 0xF0ULL,
"+0.0000000000000000130104");
826 Check ( 0xF00ULL,
"+0.0000000000000002081668");
827 Check ( 0xF000ULL,
"+0.0000000000000033306691");
828 Check ( 0xF0000ULL,
"+0.0000000000000532907052");
829 Check ( 0xF00000ULL,
"+0.0000000000008526512829");
830 Check ( 0xF000000ULL,
"+0.0000000000136424205266");
831 Check ( 0xF0000000ULL,
"+0.0000000002182787284255");
832 Check ( 0xF00000000ULL,
"+0.0000000034924596548080");
833 Check ( 0xF000000000ULL,
"+0.0000000558793544769287");
834 Check ( 0xF0000000000ULL,
"+0.0000008940696716308594");
835 Check ( 0xF00000000000ULL,
"+0.0000143051147460937500");
836 Check ( 0xF000000000000ULL,
"+0.0002288818359375000000");
837 Check ( 0xF0000000000000ULL,
"+0.0036621093750000000000");
838 Check ( 0xF00000000000000ULL,
"+0.0585937500000000000000");
839 std::cout << std::endl;
840 Check (0x7FFFFFFFFFFFFFFDULL,
"+0.4999999999999999998374", tolerance);
841 Check (0x7FFFFFFFFFFFFFFEULL,
"+0.4999999999999999998916", tolerance);
842 Check (0x7FFFFFFFFFFFFFFFULL,
"+0.4999999999999999999458", tolerance);
843 Check (0x8000000000000000ULL,
"+0.5000000000000000000000");
844 Check (0x8000000000000001ULL,
"+0.5000000000000000000542", tolerance);
845 Check (0x8000000000000002ULL,
"+0.5000000000000000001084", tolerance);
846 Check (0x8000000000000003ULL,
"+0.5000000000000000001626", tolerance);
847 std::cout << std::endl;
848 Check (0xF000000000000000ULL,
"+0.9375000000000000000000");
849 Check (0xFF00000000000000ULL,
"+0.9960937500000000000000");
850 Check (0xFFF0000000000000ULL,
"+0.9997558593750000000000");
851 Check (0xFFFF000000000000ULL,
"+0.9999847412109375000000");
852 Check (0xFFFFF00000000000ULL,
"+0.9999990463256835937500");
853 Check (0xFFFFFF0000000000ULL,
"+0.9999999403953552246094");
854 Check (0xFFFFFFF000000000ULL,
"+0.9999999962747097015381");
855 Check (0xFFFFFFFF00000000ULL,
"+0.9999999997671693563461");
856 Check (0xFFFFFFFFF0000000ULL,
"+0.9999999999854480847716");
857 Check (0xFFFFFFFFFF000000ULL,
"+0.9999999999990905052982");
858 Check (0xFFFFFFFFFFF00000ULL,
"+0.9999999999999431565811");
859 Check (0xFFFFFFFFFFFF0000ULL,
"+0.9999999999999964472863");
860 Check (0xFFFFFFFFFFFFF000ULL,
"+0.9999999999999997779554");
861 Check (0xFFFFFFFFFFFFFF00ULL,
"+0.9999999999999999861222");
862 Check (0xFFFFFFFFFFFFFFF0ULL,
"+0.9999999999999999991326");
863 Check (0xFFFFFFFFFFFFFFF5ULL,
"+0.9999999999999999994037", tolerance);
864 Check (0xFFFFFFFFFFFFFFF6ULL,
"+0.9999999999999999994579", tolerance);
865 Check (0xFFFFFFFFFFFFFFF7ULL,
"+0.9999999999999999995121", tolerance);
866 Check (0xFFFFFFFFFFFFFFF8ULL,
"+0.9999999999999999995663", tolerance);
867 Check (0xFFFFFFFFFFFFFFF9ULL,
"+0.9999999999999999996205", tolerance);
868 Check (0xFFFFFFFFFFFFFFFAULL,
"+0.9999999999999999996747", tolerance);
869 Check (0xFFFFFFFFFFFFFFFBULL,
"+0.9999999999999999997289", tolerance);
870 Check (0xFFFFFFFFFFFFFFFCULL,
"+0.9999999999999999997832", tolerance);
871 Check (0xFFFFFFFFFFFFFFFDULL,
"+0.9999999999999999998374", tolerance);
872 Check (0xFFFFFFFFFFFFFFFEULL,
"+0.9999999999999999998916", tolerance);
873 Check (0xFFFFFFFFFFFFFFFFULL,
"+0.9999999999999999999458", tolerance);
886 virtual void DoRun (
void);
895 const std::string & msg);
898 :
TestCase (
"Basic compare operations")
902 const std::string & msg)
904 bool pass =
result == expect;
907 << (pass ?
"pass " :
"FAIL ")
917 std::cout << std::endl;
932 Check ( zerof == zerof,
true,
"equality, zero");
933 Check ( onef == onef,
true,
"equality, positive");
934 Check ( mtwof == mtwof,
true,
"equality, negative");
935 Check (
zero == one,
false,
"equality false, zero");
936 Check ( one == two,
false,
"equality false, unsigned");
937 Check ( one == mone,
false,
"equality false, signed");
938 Check ( onef == one,
false,
"equality false, fraction");
939 std::cout << std::endl;
941 Check ( zerof != zerof,
false,
"inequality, zero");
942 Check ( onef != onef,
false,
"inequality, positive");
943 Check ( mtwof != mtwof,
false,
"inequality, negative");
944 Check (
zero != one,
true,
"inequality true, zero");
945 Check ( one != two,
true,
"inequality true, unsigned");
946 Check ( one != mone,
true,
"inequality true, signed");
947 Check ( onef != one,
true,
"inequality true, fraction");
948 std::cout << std::endl;
950 Check ( zerof < onef,
true,
"less, zerof");
951 Check (
zero < zerof,
true,
"less, zero");
952 Check ( one < onef,
true,
"less, positive");
953 Check ( monef < mone,
true,
"less, negative");
954 Check ( onef < one,
false,
"less, false, positive");
955 Check ( mtwo < mtwof,
false,
"less, false, negative");
956 std::cout << std::endl;
958 Check ( zerof <= zerof,
true,
"less equal, equal, zerof");
959 Check (
zero <= zerof,
true,
"less equal, less, zero");
960 Check ( onef <= onef,
true,
"less equal, equal, positive");
961 Check ( monef <= mone,
true,
"less equal, less, negative");
962 Check ( onef <= one,
false,
"less equal, false, positive");
963 Check ( mtwo <= mtwof,
false,
"less equal, false, negative");
964 std::cout << std::endl;
966 Check ( onef > zerof,
true,
"greater, zerof");
967 Check ( zerof >
zero,
true,
"greater, zero");
968 Check ( onef > one,
true,
"greater, positive");
969 Check ( mone > monef,
true,
"greater, negative");
970 Check ( one > onef,
false,
"greater, false, positive");
971 Check ( mtwof > mtwo,
false,
"greater, false, negative");
972 std::cout << std::endl;
974 Check ( zerof >= zerof,
true,
"greater equal, equal, zerof");
975 Check ( zerof >=
zero,
true,
"greater equal, greater, zero");
976 Check ( onef >= onef,
true,
"greater equal, equal, positive");
977 Check ( mone >= monef,
true,
"greater equal, greater, negative");
978 Check ( one >= onef,
false,
"greater equal, false, positive");
979 Check ( mtwof >= mtwo,
false,
"greater equal, false, negative");
980 std::cout << std::endl;
982 Check (
zero ==
false,
true,
"zero == false");
983 Check ( one ==
true,
true,
"one == true");
984 Check ( zerof !=
false,
true,
"zerof != false");
985 Check ( (!
zero) ==
true,
true,
"!zero == true");
986 Check ( (!zerof) ==
false,
true,
"!zerof == false");
987 Check ( (!one) ==
false,
true,
"!one == false");
988 Check ( (+onef) == onef,
true,
"unary positive");
989 Check ( (-onef) == monef,
true,
"unary negative");
1002 virtual void DoRun (
void);
1007 void Check (
const int64_t factor);
1018 const std::string & msg,
1019 const double tolerance = 0);
1023 :
TestCase (
"Invert and MulByInvert")
1029 const std::string & msg,
1030 const double tolerance )
1032 bool pass =
Abs (
result - expect) <= tolerance;
1038 std::cout <<
"pass: " << factor <<
": ";
1043 std::cout <<
"FAIL: " << factor <<
": "
1045 <<
" exp: " << expect
1046 <<
" tol: " << tolerance <<
") ";
1063 double tolerance = 0;
1067 tolerance = 0.000000000000000001L;
1071 CheckCase (factor, b, one,
"x * x^-1 == 1", tolerance);
1075 CheckCase (factor, c, factorI,
"1 * x^-1 == 1 / x");
1079 CheckCase (factor, d, c,
"1/x == x^-1");
1083 CheckCase (factor, e, -one,
"-x * x^-1 == -1", tolerance);
1089 std::cout << std::endl;
1109 Check (10000000000LL);
1110 Check (100000000000LL);
1111 Check (1000000000000LL);
1112 Check (10000000000000LL);
1113 Check (100000000000000LL);
1114 Check (1000000000000000LL);
1127 virtual void DoRun (
void);
1133 void Check (
const int64_t intPart);
1141 void Check (
const long double dec,
1142 const long double frac,
1143 const int64_t intPart,
1203 std::round ( 1e22 / std::pow (2.0L,
std::min (64, LDBL_MANT_DIG))) / 1e22;
1206 :
TestCase (
"Construct from floating point."),
1214 const long double frac,
1215 const int64_t intPart,
1219 long double value = dec + frac;
1280 const bool skip = (frac && (value ==
m_last));
1293 long double margin = 0;
1313 const bool pass = delta <= tolerance;
1318 std::ios_base::fmtflags ff = std::cout.flags ();
1319 std::cout << std::fixed << std::setprecision (22);
1322 << (skip ?
"skip " : (pass ?
"pass " :
"FAIL "))
1323 << std::showpos << value <<
" == "
1325 << (under ?
" (underflow)" :
"")
1332 << std::left << std::setw (43) <<
" expected"
1333 << std::right <<
Printer (expect)
1336 if (delta == tolerance)
1340 << std::left << std::setw (43) <<
" delta = tolerance"
1341 << std::right <<
Printer (delta)
1348 << std::left << std::setw (43) <<
" delta"
1349 << std::right <<
Printer (delta)
1352 << std::left << std::setw (43) <<
" tolerance"
1353 << std::right <<
Printer (tolerance)
1354 <<
" eps: " <<
epsilon <<
", margin: " << margin
1369 "int64x64_t (long double) failed");
1370 std::cout.flags (ff);
1377 std::cout << std::endl;
1379 <<
"integer: " << intPart
1390 long double v = intPart;
1392 Check (v, 0.0L, intPart, 0x0ULL);
1393 Check (v, 0.0000000000000000000542L, intPart, 0x1ULL);
1394 Check (v, 0.0000000000000000001084L, intPart, 0x2ULL);
1395 Check (v, 0.0000000000000000001626L, intPart, 0x3ULL);
1396 Check (v, 0.0000000000000000002168L, intPart, 0x4ULL);
1397 Check (v, 0.0000000000000000002711L, intPart, 0x5ULL);
1398 Check (v, 0.0000000000000000003253L, intPart, 0x6ULL);
1399 Check (v, 0.0000000000000000003795L, intPart, 0x7ULL);
1400 Check (v, 0.0000000000000000004337L, intPart, 0x8ULL);
1401 Check (v, 0.0000000000000000004879L, intPart, 0x9ULL);
1402 Check (v, 0.0000000000000000005421L, intPart, 0xAULL);
1403 Check (v, 0.0000000000000000005963L, intPart, 0xBULL);
1404 Check (v, 0.0000000000000000006505L, intPart, 0xCULL);
1405 Check (v, 0.0000000000000000007047L, intPart, 0xDULL);
1406 Check (v, 0.0000000000000000007589L, intPart, 0xEULL);
1407 Check (v, 0.0000000000000000008132L, intPart, 0xFULL);
1408 Check (v, 0.0000000000000000130104L, intPart, 0xF0ULL);
1409 Check (v, 0.0000000000000002081668L, intPart, 0xF00ULL);
1410 Check (v, 0.0000000000000033306691L, intPart, 0xF000ULL);
1411 Check (v, 0.0000000000000532907052L, intPart, 0xF0000ULL);
1412 Check (v, 0.0000000000008526512829L, intPart, 0xF00000ULL);
1413 Check (v, 0.0000000000136424205266L, intPart, 0xF000000ULL);
1414 Check (v, 0.0000000002182787284255L, intPart, 0xF0000000ULL);
1415 Check (v, 0.0000000034924596548080L, intPart, 0xF00000000ULL);
1416 Check (v, 0.0000000558793544769287L, intPart, 0xF000000000ULL);
1417 Check (v, 0.0000008940696716308594L, intPart, 0xF0000000000ULL);
1418 Check (v, 0.0000143051147460937500L, intPart, 0xF00000000000ULL);
1419 Check (v, 0.0002288818359375000000L, intPart, 0xF000000000000ULL);
1420 Check (v, 0.0036621093750000000000L, intPart, 0xF0000000000000ULL);
1421 Check (v, 0.0585937500000000000000L, intPart, 0xF00000000000000ULL);
1422 std::cout << std::endl;
1423 Check (v, 0.4999999999999999991326L, intPart, 0x7FFFFFFFFFFFFFF0ULL);
1424 Check (v, 0.4999999999999999991868L, intPart, 0x7FFFFFFFFFFFFFF1ULL);
1425 Check (v, 0.4999999999999999992411L, intPart, 0x7FFFFFFFFFFFFFF2ULL);
1426 Check (v, 0.4999999999999999992953L, intPart, 0x7FFFFFFFFFFFFFF3ULL);
1427 Check (v, 0.4999999999999999993495L, intPart, 0x7FFFFFFFFFFFFFF4ULL);
1428 Check (v, 0.4999999999999999994037L, intPart, 0x7FFFFFFFFFFFFFF5ULL);
1429 Check (v, 0.4999999999999999994579L, intPart, 0x7FFFFFFFFFFFFFF6ULL);
1430 Check (v, 0.4999999999999999995121L, intPart, 0x7FFFFFFFFFFFFFF7ULL);
1431 Check (v, 0.4999999999999999995663L, intPart, 0x7FFFFFFFFFFFFFF8ULL);
1432 Check (v, 0.4999999999999999996205L, intPart, 0x7FFFFFFFFFFFFFF9ULL);
1433 Check (v, 0.4999999999999999996747L, intPart, 0x7FFFFFFFFFFFFFFAULL);
1434 Check (v, 0.4999999999999999997289L, intPart, 0x7FFFFFFFFFFFFFFBULL);
1435 Check (v, 0.4999999999999999997832L, intPart, 0x7FFFFFFFFFFFFFFCULL);
1436 Check (v, 0.4999999999999999998374L, intPart, 0x7FFFFFFFFFFFFFFDULL);
1437 Check (v, 0.4999999999999999998916L, intPart, 0x7FFFFFFFFFFFFFFEULL);
1438 Check (v, 0.4999999999999999999458L, intPart, 0x7FFFFFFFFFFFFFFFULL);
1439 Check (v, 0.5000000000000000000000L, intPart, 0x8000000000000000ULL);
1440 Check (v, 0.5000000000000000000542L, intPart, 0x8000000000000001ULL);
1441 Check (v, 0.5000000000000000001084L, intPart, 0x8000000000000002ULL);
1442 Check (v, 0.5000000000000000001626L, intPart, 0x8000000000000003ULL);
1443 Check (v, 0.5000000000000000002168L, intPart, 0x8000000000000004ULL);
1444 Check (v, 0.5000000000000000002711L, intPart, 0x8000000000000005ULL);
1445 Check (v, 0.5000000000000000003253L, intPart, 0x8000000000000006ULL);
1446 Check (v, 0.5000000000000000003795L, intPart, 0x8000000000000007ULL);
1447 Check (v, 0.5000000000000000004337L, intPart, 0x8000000000000008ULL);
1448 Check (v, 0.5000000000000000004879L, intPart, 0x8000000000000009ULL);
1449 Check (v, 0.5000000000000000005421L, intPart, 0x800000000000000AULL);
1450 Check (v, 0.5000000000000000005963L, intPart, 0x800000000000000BULL);
1451 Check (v, 0.5000000000000000006505L, intPart, 0x800000000000000CULL);
1452 Check (v, 0.5000000000000000007047L, intPart, 0x800000000000000DULL);
1453 Check (v, 0.5000000000000000007589L, intPart, 0x800000000000000EULL);
1454 Check (v, 0.5000000000000000008132L, intPart, 0x800000000000000FULL);
1455 std::cout << std::endl;
1456 Check (v, 0.9375000000000000000000L, intPart, 0xF000000000000000ULL);
1457 Check (v, 0.9960937500000000000000L, intPart, 0xFF00000000000000ULL);
1458 Check (v, 0.9997558593750000000000L, intPart, 0xFFF0000000000000ULL);
1459 Check (v, 0.9999847412109375000000L, intPart, 0xFFFF000000000000ULL);
1460 Check (v, 0.9999990463256835937500L, intPart, 0xFFFFF00000000000ULL);
1461 Check (v, 0.9999999403953552246094L, intPart, 0xFFFFFF0000000000ULL);
1462 Check (v, 0.9999999962747097015381L, intPart, 0xFFFFFFF000000000ULL);
1463 Check (v, 0.9999999997671693563461L, intPart, 0xFFFFFFFF00000000ULL);
1464 Check (v, 0.9999999999854480847716L, intPart, 0xFFFFFFFFF0000000ULL);
1465 Check (v, 0.9999999999990905052982L, intPart, 0xFFFFFFFFFF000000ULL);
1466 Check (v, 0.9999999999999431565811L, intPart, 0xFFFFFFFFFFF00000ULL);
1467 Check (v, 0.9999999999999964472863L, intPart, 0xFFFFFFFFFFFF0000ULL);
1468 Check (v, 0.9999999999999997779554L, intPart, 0xFFFFFFFFFFFFF000ULL);
1469 Check (v, 0.9999999999999999861222L, intPart, 0xFFFFFFFFFFFFFF00ULL);
1470 Check (v, 0.9999999999999999991326L, intPart, 0xFFFFFFFFFFFFFFF0ULL);
1471 Check (v, 0.9999999999999999991868L, intPart, 0xFFFFFFFFFFFFFFF1ULL);
1472 Check (v, 0.9999999999999999992411L, intPart, 0xFFFFFFFFFFFFFFF2ULL);
1473 Check (v, 0.9999999999999999992943L, intPart, 0xFFFFFFFFFFFFFFF3ULL);
1474 Check (v, 0.9999999999999999993495L, intPart, 0xFFFFFFFFFFFFFFF4ULL);
1475 Check (v, 0.9999999999999999994037L, intPart, 0xFFFFFFFFFFFFFFF5ULL);
1476 Check (v, 0.9999999999999999994579L, intPart, 0xFFFFFFFFFFFFFFF6ULL);
1477 Check (v, 0.9999999999999999995121L, intPart, 0xFFFFFFFFFFFFFFF7ULL);
1478 Check (v, 0.9999999999999999995663L, intPart, 0xFFFFFFFFFFFFFFF8ULL);
1479 Check (v, 0.9999999999999999996205L, intPart, 0xFFFFFFFFFFFFFFF9ULL);
1480 Check (v, 0.9999999999999999996747L, intPart, 0xFFFFFFFFFFFFFFFAULL);
1481 Check (v, 0.9999999999999999997289L, intPart, 0xFFFFFFFFFFFFFFFBULL);
1482 Check (v, 0.9999999999999999997832L, intPart, 0xFFFFFFFFFFFFFFFCULL);
1483 Check (v, 0.9999999999999999998374L, intPart, 0xFFFFFFFFFFFFFFFDULL);
1484 Check (v, 0.9999999999999999998916L, intPart, 0xFFFFFFFFFFFFFFFEULL);
1485 Check (v, 0.9999999999999999999458L, intPart, 0xFFFFFFFFFFFFFFFFULL);
1488 <<
"integer:" << std::setw (4) << intPart
1501 std::cout << std::endl;
1506 std::ios_base::fmtflags ff = std::cout.flags ();
1509 <<
"FLT_RADIX: " << FLT_RADIX
1510 <<
"\n LDBL_MANT_DIG: " << LDBL_MANT_DIG
1513 <<
" (" << std::hexfloat <<
MIN_LOW <<
")" << std::defaultfloat
1517 std::cout << std::scientific << std::setprecision (21);
1530 std::cout.flags (ff);
1543 virtual void DoRun (
void);
1547 :
TestCase (
"Print the implementation")
1553 std::cout << std::endl;
1558 std::cout <<
"int64x64_t::implementation: ";
1565 default : std::cout <<
"unknown!";
1568 std::cout << std::endl;
1570 #if defined (INT64X64_USE_CAIRO) && !defined (PYTHON_SCAN)
1571 std::cout <<
"cairo_impl64: " <<
cairo_impl64 << std::endl;
1572 std::cout <<
"cairo_impl128: " <<
cairo_impl128 << std::endl;
1577 std::cout <<
"Running with valgrind" << 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 TestCsse.
std::string GetName(void) const
@ UNIT
This test suite implements a Unit Test.
Test: basic arithmetic operations.
Int64x64ArithmeticTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
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()
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const double result, const double expect, const std::string &msg)
Check the int64x64 for correctness.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const double result, const double expect, const std::string &msg)
Check the int64x64 for correctness.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Test: basic compare operations.
void Check(const bool result, const bool expect, const std::string &msg)
Check the int64x64 for correctness.
virtual void DoRun(void)
Implementation to actually run this TestCase.
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 Check(const int64_t intPart)
Check the int64x64 for correctness.
int m_deltaCount
The number of times a delta was recorded.
virtual void DoRun(void)
Implementation to actually run this TestCase.
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.
virtual void DoRun(void)
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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Test: check GetInt and Round.
Int64x64IntRoundTestCase(void)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const int64x64_t value, const int64_t expectInt, const int64_t expectRnd)
Check the int64x64 value for correctness.
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.
virtual void DoRun(void)
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(void) 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.
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.
#define RUNNING_ON_VALGRIND