20 #include "ns3/int64x64.h"
22 #include "ns3/valgrind.h"
69 Printer (
const int64_t high,
const uint64_t low)
85 m_low (value.GetLow ())
108 os << std::fixed << std::setprecision (22)
113 os << std::hex << std::setfill (
'0')
114 <<
" (0x" << std::setw (16) << p.
m_high
115 <<
" 0x" << std::setw (16) << p.
m_low <<
")"
116 << std::dec << std::setfill (
' ');
125 virtual void DoRun (
void);
126 void Check (
const int64_t hi,
const uint64_t lo);
130 :
TestCase (
"Manipulate the high and low part of every number")
136 uint64_t tolerance = 0;
144 uint64_t vLow = value.
GetLow ();
145 bool pass = ( (value.
GetHigh () == hi)
146 && ( (
Max (vLow, lo) -
Min (vLow, lo)) <= tolerance)
150 << (pass ?
"pass " :
"FAIL ")
155 "High part does not match for hi:" << hi
158 "Low part does not match for hi: " << hi
165 std::cout << std::endl;
178 Check ( 0, 0xffffffffffffffffULL - low);
182 Check ( 1, 0xffffffffffffffffULL - low);
186 Check (-1, 0xffffffffffffffffULL - low);
194 virtual void DoRun (
void);
196 const int64_t expectInt,
197 const int64_t expectRnd);
201 :
TestCase (
"Check GetInt and Round")
206 const int64_t expectInt,
207 const int64_t expectRnd)
209 int64_t vInt = value.
GetInt ();
210 int64_t vRnd = value.
Round ();
212 bool pass = (vInt == expectInt) && (vRnd == expectRnd);
214 << (pass ?
"pass " :
"FAIL ")
216 <<
" (int)-> " << std::setw (2) << vInt <<
" (expected: " << std::setw (2) << expectInt
217 <<
"), (rnd)-> " << std::setw (2) << vRnd <<
" (expected " << std::setw (2) << expectRnd
222 "Truncation to int failed");
224 "Rounding to int failed.");
230 std::cout << std::endl;
241 Check (-2.4, -2, -2);
245 Check (-3.6, -3, -4);
248 Check (-4.5, -4, -5);
256 virtual void DoRun (
void);
257 void Check (
const std::string & str,
258 const int64_t hi,
const uint64_t lo,
259 const int64_t tolerance = 0);
262 :
TestCase (
"Parse int64x64_t numbers as strings")
266 const int64_t hi,
const uint64_t lo,
267 const int64_t tolerance )
270 std::istringstream iss;
275 std::string input =
"\"" + str +
"\"";
276 uint64_t vLow = value.
GetLow ();
277 bool pass = ( (value.
GetHigh () == hi)
278 && (
Max (vLow, lo) -
Min (vLow, lo) <= tolerance)
282 << (pass ?
"pass " :
"FAIL ")
283 << std::left << std::setw (28) << input << std::right
285 <<
" expected: " <<
Printer (hi, lo) <<
" +/- " << tolerance
289 "High parts do not match for input string \""
292 "Low parts do not match for input string \""
298 std::cout << std::endl;
302 int64_t tolerance = 0;
313 Check (
"+1.0", 1, 0);
314 Check (
"001.0", 1, 0);
315 Check (
"+001.0", 1, 0);
316 Check (
"020.0", 20, 0);
317 Check (
"+020.0", 20, 0);
318 Check (
"1.0000000", 1, 0);
319 Check (
"-1.0", -1, 0, tolerance);
320 Check (
"-1.0000", -1, 0, tolerance);
321 Check (
" 1.000000000000000000054", 1, 1, tolerance);
322 Check (
"-1.000000000000000000054", (int64_t)-2, (uint64_t)-1, tolerance);
330 virtual void DoRun (
void);
331 void Check (
const std::string & str,
332 const int64_t tolerance = 0);
335 :
TestCase (
"Roundtrip int64x64_t numbers as strings")
339 const int64_t tolerance )
341 std::stringstream iss (str);
345 std::stringstream oss;
346 oss << std::scientific << std::setprecision (21) << expect;
350 bool pass =
Abs (value - expect) <=
int64x64_t (0, tolerance + 1);
352 std::string input =
"\"" + str +
"\"";
353 std::string output =
"\"" + oss.str () +
"\"";
358 << (pass ?
"pass " :
"FAIL ")
359 <<
" in: " << std::left << std::setw (28) << input
360 <<
" out: " << std::left << std::setw (28) << output
367 << (pass ?
"pass " :
"FAIL ")
368 <<
" in: " << std::left << std::setw (28) << input
369 << std::right <<
Printer (expect)
372 << std::setw (19) <<
" "
373 <<
" out: " << std::left << std::setw (28) << output
374 << std::right <<
Printer (value)
379 "Converted string does not match expected string");
385 std::cout << std::endl;
389 int64_t tolerance = 0;
396 Check (
"+1.000000000000000000000");
397 Check (
"+20.000000000000000000000");
398 Check (
"+0.000000000000000000000", tolerance);
399 Check (
"-1.000000000000000000000", tolerance);
400 Check (
"+1.084467440737095516158", tolerance);
401 Check (
"-2.084467440737095516158", tolerance);
402 Check (
"+3.184467440737095516179", tolerance);
403 Check (
"-4.184467440737095516179", tolerance);
411 virtual void DoRun (
void);
412 void Check (
const int test,
414 void Check (
const int test,
420 :
TestCase (
"Basic arithmetic operations")
436 bool pass =
Abs (value - expect) <= tolerance;
439 << (pass ?
"pass " :
"FAIL ")
440 << test <<
": " << value <<
" == " << expect
441 <<
" (+/- " << tolerance <<
")"
445 "Arithmetic failure in test case " << test);
457 std::cout << std::endl;
464 Check ( 3, one - two, -one );
465 Check ( 4, one - (-one ), two );
466 Check ( 5, (-one ) - (-two ), one );
467 Check ( 6, (-one ) - two, -thre );
471 Check ( 9, one + one, two );
472 Check (10, one + two, thre );
474 Check (12, (-one ) + (-two ), -thre );
475 Check (13, (-one ) + two, one );
480 Check (17, one * one, one );
481 Check (18, one * (-one ), -one );
482 Check (19, (-one ) * (-one ), one );
484 Check (20, (two * thre ) / thre, two );
489 Check (21, frac, 0.75);
490 Check (22, fplf2, 1.3125);
497 Check (23, zerof, frac);
501 Check (25, zerof - onef, -one );
503 Check (27, onef - twof, -one );
504 Check (28, onef - (-onef), twof + frac );
505 Check (29, (-onef) - (-twof), one );
506 Check (30, (-onef) - twof, -thref - frac );
508 Check (31, zerof + zerof, zerof + frac );
509 Check (32, zerof + onef, onef + frac );
510 Check (33, onef + onef, twof + frac );
511 Check (34, onef + twof, thref + frac );
513 Check (36, (-onef) + (-twof), -thref - frac );
514 Check (37, (-onef) + twof, one );
516 Check (38, zerof * zerof, frac * frac );
518 Check (40, zerof * one, frac );
520 Check (41, zerof * onef, fplf2 );
521 Check (42, zerof * (-onef), -fplf2 );
522 Check (43, onef * onef, onef + fplf2 );
523 Check (44, onef * (-onef), -onef - fplf2 );
524 Check (45, (-onef) * (-onef), onef + fplf2 );
528 Check (46, (two * thre ) / thre, two );
529 Check (47, (twof * thref) / thref, twof );
532 Check (48, (two / thre) * thre, two, 2 * tol1 );
533 Check (49, (twof / thref) * thref, twof, 3 * tol1 );
539 int64x64_t (1999999999, 0xfffffffffffffffeULL));
556 virtual void DoRun (
void);
557 void Check (
const double result,
const double expect,
558 const std::string & msg);
562 :
TestCase (
"Test case for bug 455")
566 const std::string & msg)
568 bool pass = result == expect;
571 << (pass ?
"pass " :
"FAIL ")
573 <<
" exp: " << expect
583 std::cout << std::endl;
597 Check (a.
GetDouble (), -2.5,
"Test sign, first operation negative");
617 virtual void DoRun (
void);
618 void Check (
const double result,
const double expect,
619 const std::string & msg);
623 :
TestCase (
"Test case for bug 863")
627 const std::string & msg)
629 bool pass = result == expect;
632 << (pass ?
"pass " :
"FAIL ")
634 <<
" exp: " << expect
644 std::cout << std::endl;
657 Check (a.
GetDouble (), -0.5,
"Check that we actually convert doubles correctly");
679 virtual void DoRun (
void);
680 void Check (
const uint64_t low,
const std::string & value,
681 const int64_t tolerance = 0);
685 :
TestCase (
"Test case for bug 1786")
689 const std::string & str,
690 const int64_t tolerance )
693 std::ostringstream oss;
694 oss << std::scientific << std::setprecision (22) << value;
698 bool pass = oss.str () == str;
701 << (pass ?
"pass " :
"FAIL ")
702 <<
" 0x" << std::hex << std::setw (16) << low << std::dec
703 <<
" = " << oss.str ();
706 std::cout <<
", expected " << str;
708 std::cout << std::endl;
711 "Fraction string not correct");
719 <<
" 0x" << std::hex << std::setw (16) << low << std::dec
720 <<
" = " << oss.str ()
721 <<
", expected " << str
729 std::cout << std::endl;
733 int64_t tolerance = 0;
744 Check ( 1ULL,
"+0.0000000000000000000542");
745 Check ( 2ULL,
"+0.0000000000000000001084");
746 Check ( 3ULL,
"+0.0000000000000000001626");
747 Check ( 4ULL,
"+0.0000000000000000002168");
748 Check ( 5ULL,
"+0.0000000000000000002710");
749 Check ( 6ULL,
"+0.0000000000000000003253");
750 Check ( 7ULL,
"+0.0000000000000000003795");
751 Check ( 8ULL,
"+0.0000000000000000004337");
752 Check ( 9ULL,
"+0.0000000000000000004879");
753 Check ( 0xAULL,
"+0.0000000000000000005421");
754 Check ( 0xFULL,
"+0.0000000000000000008132");
755 Check ( 0xF0ULL,
"+0.0000000000000000130104");
756 Check ( 0xF00ULL,
"+0.0000000000000002081668");
757 Check ( 0xF000ULL,
"+0.0000000000000033306691");
758 Check ( 0xF0000ULL,
"+0.0000000000000532907052");
759 Check ( 0xF00000ULL,
"+0.0000000000008526512829");
760 Check ( 0xF000000ULL,
"+0.0000000000136424205266");
761 Check ( 0xF0000000ULL,
"+0.0000000002182787284255");
762 Check ( 0xF00000000ULL,
"+0.0000000034924596548080");
763 Check ( 0xF000000000ULL,
"+0.0000000558793544769287");
764 Check ( 0xF0000000000ULL,
"+0.0000008940696716308594");
765 Check ( 0xF00000000000ULL,
"+0.0000143051147460937500");
766 Check ( 0xF000000000000ULL,
"+0.0002288818359375000000");
767 Check ( 0xF0000000000000ULL,
"+0.0036621093750000000000");
768 Check ( 0xF00000000000000ULL,
"+0.0585937500000000000000");
769 std::cout << std::endl;
770 Check (0x7FFFFFFFFFFFFFFDULL,
"+0.4999999999999999998374", tolerance);
771 Check (0x7FFFFFFFFFFFFFFEULL,
"+0.4999999999999999998916", tolerance);
772 Check (0x7FFFFFFFFFFFFFFFULL,
"+0.4999999999999999999458", tolerance);
773 Check (0x8000000000000000ULL,
"+0.5000000000000000000000");
774 Check (0x8000000000000001ULL,
"+0.5000000000000000000542", tolerance);
775 Check (0x8000000000000002ULL,
"+0.5000000000000000001084", tolerance);
776 Check (0x8000000000000003ULL,
"+0.5000000000000000001626", tolerance);
777 std::cout << std::endl;
778 Check (0xF000000000000000ULL,
"+0.9375000000000000000000");
779 Check (0xFF00000000000000ULL,
"+0.9960937500000000000000");
780 Check (0xFFF0000000000000ULL,
"+0.9997558593750000000000");
781 Check (0xFFFF000000000000ULL,
"+0.9999847412109375000000");
782 Check (0xFFFFF00000000000ULL,
"+0.9999990463256835937500");
783 Check (0xFFFFFF0000000000ULL,
"+0.9999999403953552246094");
784 Check (0xFFFFFFF000000000ULL,
"+0.9999999962747097015381");
785 Check (0xFFFFFFFF00000000ULL,
"+0.9999999997671693563461");
786 Check (0xFFFFFFFFF0000000ULL,
"+0.9999999999854480847716");
787 Check (0xFFFFFFFFFF000000ULL,
"+0.9999999999990905052982");
788 Check (0xFFFFFFFFFFF00000ULL,
"+0.9999999999999431565811");
789 Check (0xFFFFFFFFFFFF0000ULL,
"+0.9999999999999964472863");
790 Check (0xFFFFFFFFFFFFF000ULL,
"+0.9999999999999997779554");
791 Check (0xFFFFFFFFFFFFFF00ULL,
"+0.9999999999999999861222");
792 Check (0xFFFFFFFFFFFFFFF0ULL,
"+0.9999999999999999991326");
793 Check (0xFFFFFFFFFFFFFFF5ULL,
"+0.9999999999999999994037", tolerance);
794 Check (0xFFFFFFFFFFFFFFF6ULL,
"+0.9999999999999999994579", tolerance);
795 Check (0xFFFFFFFFFFFFFFF7ULL,
"+0.9999999999999999995121", tolerance);
796 Check (0xFFFFFFFFFFFFFFF8ULL,
"+0.9999999999999999995663", tolerance);
797 Check (0xFFFFFFFFFFFFFFF9ULL,
"+0.9999999999999999996205", tolerance);
798 Check (0xFFFFFFFFFFFFFFFAULL,
"+0.9999999999999999996747", tolerance);
799 Check (0xFFFFFFFFFFFFFFFBULL,
"+0.9999999999999999997289", tolerance);
800 Check (0xFFFFFFFFFFFFFFFCULL,
"+0.9999999999999999997832", tolerance);
801 Check (0xFFFFFFFFFFFFFFFDULL,
"+0.9999999999999999998374", tolerance);
802 Check (0xFFFFFFFFFFFFFFFEULL,
"+0.9999999999999999998916", tolerance);
803 Check (0xFFFFFFFFFFFFFFFFULL,
"+0.9999999999999999999458", tolerance);
811 virtual void DoRun (
void);
813 void Check (
const bool result,
const bool expect,
814 const std::string & msg);
817 :
TestCase (
"Basic compare operations")
821 const std::string & msg)
823 bool pass = result == expect;
826 << (pass ?
"pass " :
"FAIL ")
836 std::cout << std::endl;
851 Check ( zerof == zerof,
true,
"equality, zero");
852 Check ( onef == onef,
true,
"equality, positive");
853 Check ( mtwof == mtwof,
true,
"equality, negative");
854 Check (
zero == one,
false,
"equality false, zero");
855 Check ( one == two,
false,
"equality false, unsigned");
856 Check ( one == mone,
false,
"equality false, signed");
857 Check ( onef == one,
false,
"equality false, fraction");
858 std::cout << std::endl;
860 Check ( zerof != zerof,
false,
"inequality, zero");
861 Check ( onef != onef,
false,
"inequality, positive");
862 Check ( mtwof != mtwof,
false,
"inequality, negative");
863 Check (
zero != one,
true,
"inequality true, zero");
864 Check ( one != two,
true,
"inequality true, unsigned");
865 Check ( one != mone,
true,
"inequality true, signed");
866 Check ( onef != one,
true,
"inequality true, fraction");
867 std::cout << std::endl;
869 Check ( zerof < onef,
true,
"less, zerof");
870 Check (
zero < zerof,
true,
"less, zero");
871 Check ( one < onef,
true,
"less, positive");
872 Check ( monef < mone,
true,
"less, negative");
873 Check ( onef < one,
false,
"less, false, positive");
874 Check ( mtwo < mtwof,
false,
"less, false, negative");
875 std::cout << std::endl;
877 Check ( zerof <= zerof,
true,
"less equal, equal, zerof");
878 Check (
zero <= zerof,
true,
"less equal, less, zero");
879 Check ( onef <= onef,
true,
"less equal, equal, positive");
880 Check ( monef <= mone,
true,
"less equal, less, negative");
881 Check ( onef <= one,
false,
"less equal, false, positive");
882 Check ( mtwo <= mtwof,
false,
"less equal, false, negative");
883 std::cout << std::endl;
885 Check ( onef > zerof,
true,
"greater, zerof");
886 Check ( zerof >
zero,
true,
"greater, zero");
887 Check ( onef > one,
true,
"greater, positive");
888 Check ( mone > monef,
true,
"greater, negative");
889 Check ( one > onef,
false,
"greater, false, positive");
890 Check ( mtwof > mtwo,
false,
"greater, false, negative");
891 std::cout << std::endl;
893 Check ( zerof >= zerof,
true,
"greater equal, equal, zerof");
894 Check ( zerof >=
zero,
true,
"greater equal, greater, zero");
895 Check ( onef >= onef,
true,
"greater equal, equal, positive");
896 Check ( mone >= monef,
true,
"greater equal, greater, negative");
897 Check ( one >= onef,
false,
"greater equal, false, positive");
898 Check ( mtwof >= mtwo,
false,
"greater equal, false, negative");
899 std::cout << std::endl;
901 Check (
zero ==
false,
true,
"zero == false");
902 Check ( one ==
true,
true,
"one == true");
903 Check ( zerof !=
false,
true,
"zerof != false");
904 Check ( (!
zero) ==
true,
true,
"!zero == true");
905 Check ( (!zerof) ==
false,
true,
"!zerof == false");
906 Check ( (!one) ==
false,
true,
"!one == false");
907 Check ( (+onef) == onef,
true,
"unary positive");
908 Check ( (-onef) == monef,
true,
"unary negative");
916 virtual void DoRun (
void);
917 void Check (
const int64_t factor);
920 const std::string & msg,
921 const double tolerance = 0);
925 :
TestCase (
"Invert and MulByInvert")
931 const std::string & msg,
932 const double tolerance )
934 bool pass =
Abs (result - expect) <= tolerance;
940 std::cout <<
"pass: " << factor <<
": ";
945 std::cout <<
"FAIL: " << factor <<
": "
946 <<
"(res: " << result
947 <<
" exp: " << expect
948 <<
" tol: " << tolerance <<
") ";
965 double tolerance = 0;
969 tolerance = 0.000000000000000001L;
973 CheckCase (factor, b, one,
"x * x^-1 == 1", tolerance);
977 CheckCase (factor, c, factorI,
"1 * x^-1 == 1 / x");
985 CheckCase (factor, e, -one,
"-x * x^-1 == -1", tolerance);
991 std::cout << std::endl;
1011 Check (10000000000LL);
1012 Check (100000000000LL);
1013 Check (1000000000000LL);
1014 Check (10000000000000LL);
1015 Check (100000000000000LL);
1016 Check (1000000000000000LL);
1024 virtual void DoRun (
void);
1025 void Check (
const int64_t intPart);
1026 void Check (
const long double value,
1027 const int64_t intPart,
1037 :
TestCase (
"Construct from floating point.")
1042 const int64_t intPart,
1054 long double margin = 0;
1072 const bool skip = value ==
m_last;
1073 const bool pass = delta <= tolerance;
1076 std::ios_base::fmtflags ff = std::cout.flags ();
1077 std::cout << std::fixed << std::setprecision (22);
1080 << (skip ?
"skip " : (pass ?
"pass " :
"FAIL "))
1081 << std::showpos << value <<
" == "
1089 << std::left << std::setw (43) <<
" expected"
1090 << std::right <<
Printer (expect)
1093 if (delta == tolerance)
1096 << std::left << std::setw (43) <<
" delta = tolerance"
1097 << std::right <<
Printer (delta)
1103 << std::left << std::setw (43) <<
" delta"
1104 << std::right <<
Printer (delta)
1107 << std::left << std::setw (43) <<
" +/-"
1108 << std::right <<
Printer (tolerance)
1121 "int64x64_t (long double) failed");
1123 std::cout.flags (ff);
1130 std::cout << std::endl;
1132 <<
"integer: " << intPart
1134 m_last =
static_cast<long double> (intPart);
1138 long double v =
static_cast<long double> (intPart);
1140 Check (v + 0.0000000000000000000542L, intPart, 0x1ULL);
1141 Check (v + 0.0000000000000000001084L, intPart, 0x2ULL);
1142 Check (v + 0.0000000000000000001626L, intPart, 0x3ULL);
1143 Check (v + 0.0000000000000000002168L, intPart, 0x4ULL);
1144 Check (v + 0.0000000000000000002710L, intPart, 0x5ULL);
1145 Check (v + 0.0000000000000000003253L, intPart, 0x6ULL);
1146 Check (v + 0.0000000000000000003795L, intPart, 0x7ULL);
1147 Check (v + 0.0000000000000000004337L, intPart, 0x8ULL);
1148 Check (v + 0.0000000000000000004879L, intPart, 0x9ULL);
1149 Check (v + 0.0000000000000000005421L, intPart, 0xAULL);
1150 Check (v + 0.0000000000000000008132L, intPart, 0xFULL);
1151 Check (v + 0.0000000000000000130104L, intPart, 0xF0ULL);
1152 Check (v + 0.0000000000000002081668L, intPart, 0xF00ULL);
1153 Check (v + 0.0000000000000033306691L, intPart, 0xF000ULL);
1154 Check (v + 0.0000000000000532907052L, intPart, 0xF0000ULL);
1155 Check (v + 0.0000000000008526512829L, intPart, 0xF00000ULL);
1156 Check (v + 0.0000000000136424205266L, intPart, 0xF000000ULL);
1157 Check (v + 0.0000000002182787284255L, intPart, 0xF0000000ULL);
1158 Check (v + 0.0000000034924596548080L, intPart, 0xF00000000ULL);
1159 Check (v + 0.0000000558793544769287L, intPart, 0xF000000000ULL);
1160 Check (v + 0.0000008940696716308594L, intPart, 0xF0000000000ULL);
1161 Check (v + 0.0000143051147460937500L, intPart, 0xF00000000000ULL);
1162 Check (v + 0.0002288818359375000000L, intPart, 0xF000000000000ULL);
1163 Check (v + 0.0036621093750000000000L, intPart, 0xF0000000000000ULL);
1164 Check (v + 0.0585937500000000000000L, intPart, 0xF00000000000000ULL);
1165 std::cout << std::endl;
1166 Check (v + 0.4999999999999999998374L, intPart, 0x7FFFFFFFFFFFFFFDULL);
1167 Check (v + 0.4999999999999999998916L, intPart, 0x7FFFFFFFFFFFFFFEULL);
1168 Check (v + 0.4999999999999999999458L, intPart, 0x7FFFFFFFFFFFFFFFULL);
1169 Check (v + 0.5000000000000000000000L, intPart, 0x8000000000000000ULL);
1170 Check (v + 0.5000000000000000000542L, intPart, 0x8000000000000001ULL);
1171 Check (v + 0.5000000000000000001084L, intPart, 0x8000000000000002ULL);
1172 Check (v + 0.5000000000000000001626L, intPart, 0x8000000000000003ULL);
1173 std::cout << std::endl;
1174 Check (v + 0.9375000000000000000000L, intPart, 0xF000000000000000ULL);
1175 Check (v + 0.9960937500000000000000L, intPart, 0xFF00000000000000ULL);
1176 Check (v + 0.9997558593750000000000L, intPart, 0xFFF0000000000000ULL);
1177 Check (v + 0.9999847412109375000000L, intPart, 0xFFFF000000000000ULL);
1178 Check (v + 0.9999990463256835937500L, intPart, 0xFFFFF00000000000ULL);
1179 Check (v + 0.9999999403953552246094L, intPart, 0xFFFFFF0000000000ULL);
1180 Check (v + 0.9999999962747097015381L, intPart, 0xFFFFFFF000000000ULL);
1181 Check (v + 0.9999999997671693563461L, intPart, 0xFFFFFFFF00000000ULL);
1182 Check (v + 0.9999999999854480847716L, intPart, 0xFFFFFFFFF0000000ULL);
1183 Check (v + 0.9999999999990905052982L, intPart, 0xFFFFFFFFFF000000ULL);
1184 Check (v + 0.9999999999999431565811L, intPart, 0xFFFFFFFFFFF00000ULL);
1185 Check (v + 0.9999999999999964472863L, intPart, 0xFFFFFFFFFFFF0000ULL);
1186 Check (v + 0.9999999999999997779554L, intPart, 0xFFFFFFFFFFFFF000ULL);
1187 Check (v + 0.9999999999999999861222L, intPart, 0xFFFFFFFFFFFFFF00ULL);
1188 Check (v + 0.9999999999999999991326L, intPart, 0xFFFFFFFFFFFFFFF0ULL);
1189 Check (v + 0.9999999999999999994037L, intPart, 0xFFFFFFFFFFFFFFF5ULL);
1190 Check (v + 0.9999999999999999994579L, intPart, 0xFFFFFFFFFFFFFFF6ULL);
1191 Check (v + 0.9999999999999999995121L, intPart, 0xFFFFFFFFFFFFFFF7ULL);
1192 Check (v + 0.9999999999999999995663L, intPart, 0xFFFFFFFFFFFFFFF8ULL);
1193 Check (v + 0.9999999999999999996205L, intPart, 0xFFFFFFFFFFFFFFF9ULL);
1194 Check (v + 0.9999999999999999996747L, intPart, 0xFFFFFFFFFFFFFFFAULL);
1195 Check (v + 0.9999999999999999997289L, intPart, 0xFFFFFFFFFFFFFFFBULL);
1196 Check (v + 0.9999999999999999997832L, intPart, 0xFFFFFFFFFFFFFFFCULL);
1197 Check (v + 0.9999999999999999998374L, intPart, 0xFFFFFFFFFFFFFFFDULL);
1198 Check (v + 0.9999999999999999998916L, intPart, 0xFFFFFFFFFFFFFFFEULL);
1199 Check (v + 0.9999999999999999999458L, intPart, 0xFFFFFFFFFFFFFFFFULL);
1202 <<
"integer: " << intPart
1211 std::cout << std::endl;
1216 std::ios_base::fmtflags ff = std::cout.flags ();
1217 std::cout << std::scientific << std::setprecision (21);
1234 std::cout.flags (ff);
1242 virtual void DoRun (
void);
1246 :
TestCase (
"Print the implementation")
1252 std::cout << std::endl;
1257 std::cout <<
"int64x64_t::implementation: ";
1264 default : std::cout <<
"unknown!";
1267 std::cout << std::endl;
1269 #if defined (INT64X64_USE_CAIRO) && !defined (PYTHON_SCAN)
1270 std::cout <<
"cairo_impl64: " <<
cairo_impl64 << std::endl;
1271 std::cout <<
"cairo_impl128: " <<
cairo_impl128 << std::endl;
1276 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.
void Check(const int test, const int64x64_t value, const int64x64_t expect)
Int64x64ArithmeticTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const uint64_t low, const std::string &value, const int64_t tolerance=0)
Int64x64Bug1786TestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const double result, const double expect, const std::string &msg)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const double result, const double expect, const std::string &msg)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const bool result, const bool expect, const std::string &msg)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Int64x64CompareTestCase()
void Check(const int64_t intPart)
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const int64_t hi, const uint64_t lo)
virtual void DoRun(void)
Implementation to actually run this TestCase.
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)
void CheckCase(const uint64_t factor, const int64x64_t result, const int64x64_t expect, const std::string &msg, const double tolerance=0)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const int64_t factor)
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.
int64_t GetInt(void) const
Truncate to an integer.
@ int128_impl
Native int128_t implementation.
@ ld_impl
long double implementation.
@ cairo_impl
Cairo wideint implementation.
int64_t Round(void) const
Round to the nearest int.
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.
int64_t GetHigh(void) const
Get the integer portion.
uint64_t GetLow(void) const
Get the fractional portion of this value, unscaled.
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.
std::ostream & operator<<(std::ostream &os, const Printer &p)
ns3::int64x64::test::Int64x64TestSuite g_int64x64TestSuite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define RUNNING_ON_VALGRIND