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);
195 void Check (
const std::string & str,
196 const int64_t hi,
const uint64_t lo,
197 const int64_t tolerance = 0);
200 :
TestCase (
"Parse int64x64_t numbers as strings")
204 const int64_t hi,
const uint64_t lo,
205 const int64_t tolerance )
208 std::istringstream iss;
213 std::string input =
"\"" + str +
"\"";
214 uint64_t vLow = value.
GetLow ();
215 bool pass = ( (value.GetHigh () == hi)
216 && (
Max (vLow, lo) -
Min (vLow, lo) <= tolerance)
220 << (pass ?
"pass " :
"FAIL ")
221 << std::left << std::setw (28) << input << std::right
223 <<
" expected: " <<
Printer (hi, lo) <<
" +/- " << tolerance
227 "High parts do not match for input string \"" 230 "Low parts do not match for input string \"" 236 std::cout << std::endl;
240 int64_t tolerance = 0;
251 Check (
"+1.0", 1, 0);
252 Check (
"001.0", 1, 0);
253 Check (
"+001.0", 1, 0);
254 Check (
"020.0", 20, 0);
255 Check (
"+020.0", 20, 0);
256 Check (
"1.0000000", 1, 0);
257 Check (
"-1.0", -1, 0, tolerance);
258 Check (
"-1.0000", -1, 0, tolerance);
259 Check (
" 1.000000000000000000054", 1, 1, tolerance);
260 Check (
"-1.000000000000000000054", (int64_t)-2, (uint64_t)-1, tolerance);
268 virtual void DoRun (
void);
269 void Check (
const std::string & str,
270 const int64_t tolerance = 0);
273 :
TestCase (
"Roundtrip int64x64_t numbers as strings")
277 const int64_t tolerance )
279 std::stringstream iss (str);
283 std::stringstream oss;
284 oss << std::scientific << std::setprecision (21) << expect;
288 bool pass =
Abs (value - expect) <=
int64x64_t (0, tolerance + 1);
290 std::string input =
"\"" + str +
"\"";
291 std::string output =
"\"" + oss.str () +
"\"";
296 << (pass ?
"pass " :
"FAIL ")
297 <<
" in: " << std::left << std::setw (28) << input
298 <<
" out: " << std::left << std::setw (28) << output
305 << (pass ?
"pass " :
"FAIL ")
306 <<
" in: " << std::left << std::setw (28) << input
307 << std::right <<
Printer (expect)
310 << std::setw (19) <<
" " 311 <<
" out: " << std::left << std::setw (28) << output
312 << std::right <<
Printer (value)
317 "Converted string does not match expected string");
323 std::cout << std::endl;
327 int64_t tolerance = 0;
334 Check (
"+1.000000000000000000000");
335 Check (
"+20.000000000000000000000");
336 Check (
"+0.000000000000000000000", tolerance);
337 Check (
"-1.000000000000000000000", tolerance);
338 Check (
"+1.084467440737095516158", tolerance);
339 Check (
"-2.084467440737095516158", tolerance);
340 Check (
"+3.184467440737095516179", tolerance);
341 Check (
"-4.184467440737095516179", tolerance);
349 virtual void DoRun (
void);
350 void Check (
const int test,
352 void Check (
const int test,
358 :
TestCase (
"Basic arithmetic operations")
374 bool pass =
Abs (value - expect) <= tolerance;
377 << (pass ?
"pass " :
"FAIL ")
378 << test <<
": " << value <<
" == " << expect
379 <<
" (+/- " << tolerance <<
")" 383 "Arithmetic failure in test case " << test);
395 std::cout << std::endl;
402 Check ( 3, one - two, -one );
403 Check ( 4, one - (-one ), two );
404 Check ( 5, (-one ) - (-two ), one );
405 Check ( 6, (-one ) - two, -thre );
409 Check ( 9, one + one, two );
410 Check (10, one + two, thre );
412 Check (12, (-one ) + (-two ), -thre );
413 Check (13, (-one ) + two, one );
418 Check (17, one * one, one );
419 Check (18, one * (-one ), -one );
420 Check (19, (-one ) * (-one ), one );
422 Check (20, (two * thre ) / thre, two );
427 Check (21, frac, 0.75);
428 Check (22, fplf2, 1.3125);
435 Check (23, zerof, frac);
439 Check (25, zerof - onef, -one );
441 Check (27, onef - twof, -one );
442 Check (28, onef - (-onef), twof + frac );
443 Check (29, (-onef) - (-twof), one );
444 Check (30, (-onef) - twof, -thref - frac );
446 Check (31, zerof + zerof, zerof + frac );
447 Check (32, zerof + onef, onef + frac );
448 Check (33, onef + onef, twof + frac );
449 Check (34, onef + twof, thref + frac );
451 Check (36, (-onef) + (-twof), -thref - frac );
452 Check (37, (-onef) + twof, one );
454 Check (38, zerof * zerof, frac * frac );
456 Check (40, zerof * one, frac );
458 Check (41, zerof * onef, fplf2 );
459 Check (42, zerof * (-onef), -fplf2 );
460 Check (43, onef * onef, onef + fplf2 );
461 Check (44, onef * (-onef), -onef - fplf2 );
462 Check (45, (-onef) * (-onef), onef + fplf2 );
466 Check (46, (two * thre ) / thre, two );
467 Check (47, (twof * thref) / thref, twof );
470 Check (48, (two / thre) * thre, two, 2 * tol1 );
471 Check (49, (twof / thref) * thref, twof, 3 * tol1 );
477 int64x64_t (1999999999, 0xfffffffffffffffeULL));
494 virtual void DoRun (
void);
495 void Check (
const double result,
const double expect,
496 const std::string & msg);
500 :
TestCase (
"Test case for bug 455")
504 const std::string & msg)
506 bool pass = result == expect;
509 << (pass ?
"pass " :
"FAIL ")
511 <<
" exp: " << expect
521 std::cout << std::endl;
531 Check (a.GetDouble (), 2.5,
"Simple test for multiplication");
535 Check (a.GetDouble (), -2.5,
"Test sign, first operation negative");
539 Check (a.GetDouble (), 2.5,
"both operands negative");
543 Check (a.GetDouble (), -2.5,
"only second operand negative");
555 virtual void DoRun (
void);
556 void Check (
const double result,
const double expect,
557 const std::string & msg);
561 :
TestCase (
"Test case for bug 863")
565 const std::string & msg)
567 bool pass = result == expect;
570 << (pass ?
"pass " :
"FAIL ")
572 <<
" exp: " << expect
582 std::cout << std::endl;
592 Check (a.GetDouble (), 1.0,
"Simple test for division");
595 Check (a.GetDouble (), -0.5,
"Check that we actually convert doubles correctly");
598 Check (a.GetDouble (), -1.0,
"first argument negative");
602 Check (a.GetDouble (), -1.0,
"second argument negative");
606 Check (a.GetDouble (), 1.0,
"both arguments negative");
617 virtual void DoRun (
void);
618 void Check (
const uint64_t low,
const std::string & value,
619 const int64_t tolerance = 0);
623 :
TestCase (
"Test case for bug 1786")
627 const std::string & str,
628 const int64_t tolerance )
631 std::ostringstream oss;
632 oss << std::scientific << std::setprecision (22) << value;
636 bool pass = oss.str () == str;
639 << (pass ?
"pass " :
"FAIL ")
640 <<
" 0x" << std::hex << std::setw (16) << low << std::dec
641 <<
" = " << oss.str ();
644 std::cout <<
", expected " << str;
646 std::cout << std::endl;
649 "Fraction string not correct");
657 <<
" 0x" << std::hex << std::setw (16) << low << std::dec
658 <<
" = " << oss.str ()
659 <<
", expected " << str
667 std::cout << std::endl;
671 int64_t tolerance = 0;
682 Check ( 1ULL,
"+0.0000000000000000000542");
683 Check ( 2ULL,
"+0.0000000000000000001084");
684 Check ( 3ULL,
"+0.0000000000000000001626");
685 Check ( 4ULL,
"+0.0000000000000000002168");
686 Check ( 5ULL,
"+0.0000000000000000002710");
687 Check ( 6ULL,
"+0.0000000000000000003253");
688 Check ( 7ULL,
"+0.0000000000000000003795");
689 Check ( 8ULL,
"+0.0000000000000000004337");
690 Check ( 9ULL,
"+0.0000000000000000004879");
691 Check ( 0xAULL,
"+0.0000000000000000005421");
692 Check ( 0xFULL,
"+0.0000000000000000008132");
693 Check ( 0xF0ULL,
"+0.0000000000000000130104");
694 Check ( 0xF00ULL,
"+0.0000000000000002081668");
695 Check ( 0xF000ULL,
"+0.0000000000000033306691");
696 Check ( 0xF0000ULL,
"+0.0000000000000532907052");
697 Check ( 0xF00000ULL,
"+0.0000000000008526512829");
698 Check ( 0xF000000ULL,
"+0.0000000000136424205266");
699 Check ( 0xF0000000ULL,
"+0.0000000002182787284255");
700 Check ( 0xF00000000ULL,
"+0.0000000034924596548080");
701 Check ( 0xF000000000ULL,
"+0.0000000558793544769287");
702 Check ( 0xF0000000000ULL,
"+0.0000008940696716308594");
703 Check ( 0xF00000000000ULL,
"+0.0000143051147460937500");
704 Check ( 0xF000000000000ULL,
"+0.0002288818359375000000");
705 Check ( 0xF0000000000000ULL,
"+0.0036621093750000000000");
706 Check ( 0xF00000000000000ULL,
"+0.0585937500000000000000");
707 std::cout << std::endl;
708 Check (0x7FFFFFFFFFFFFFFDULL,
"+0.4999999999999999998374", tolerance);
709 Check (0x7FFFFFFFFFFFFFFEULL,
"+0.4999999999999999998916", tolerance);
710 Check (0x7FFFFFFFFFFFFFFFULL,
"+0.4999999999999999999458", tolerance);
711 Check (0x8000000000000000ULL,
"+0.5000000000000000000000");
712 Check (0x8000000000000001ULL,
"+0.5000000000000000000542", tolerance);
713 Check (0x8000000000000002ULL,
"+0.5000000000000000001084", tolerance);
714 Check (0x8000000000000003ULL,
"+0.5000000000000000001626", tolerance);
715 std::cout << std::endl;
716 Check (0xF000000000000000ULL,
"+0.9375000000000000000000");
717 Check (0xFF00000000000000ULL,
"+0.9960937500000000000000");
718 Check (0xFFF0000000000000ULL,
"+0.9997558593750000000000");
719 Check (0xFFFF000000000000ULL,
"+0.9999847412109375000000");
720 Check (0xFFFFF00000000000ULL,
"+0.9999990463256835937500");
721 Check (0xFFFFFF0000000000ULL,
"+0.9999999403953552246094");
722 Check (0xFFFFFFF000000000ULL,
"+0.9999999962747097015381");
723 Check (0xFFFFFFFF00000000ULL,
"+0.9999999997671693563461");
724 Check (0xFFFFFFFFF0000000ULL,
"+0.9999999999854480847716");
725 Check (0xFFFFFFFFFF000000ULL,
"+0.9999999999990905052982");
726 Check (0xFFFFFFFFFFF00000ULL,
"+0.9999999999999431565811");
727 Check (0xFFFFFFFFFFFF0000ULL,
"+0.9999999999999964472863");
728 Check (0xFFFFFFFFFFFFF000ULL,
"+0.9999999999999997779554");
729 Check (0xFFFFFFFFFFFFFF00ULL,
"+0.9999999999999999861222");
730 Check (0xFFFFFFFFFFFFFFF0ULL,
"+0.9999999999999999991326");
731 Check (0xFFFFFFFFFFFFFFF5ULL,
"+0.9999999999999999994037", tolerance);
732 Check (0xFFFFFFFFFFFFFFF6ULL,
"+0.9999999999999999994579", tolerance);
733 Check (0xFFFFFFFFFFFFFFF7ULL,
"+0.9999999999999999995121", tolerance);
734 Check (0xFFFFFFFFFFFFFFF8ULL,
"+0.9999999999999999995663", tolerance);
735 Check (0xFFFFFFFFFFFFFFF9ULL,
"+0.9999999999999999996205", tolerance);
736 Check (0xFFFFFFFFFFFFFFFAULL,
"+0.9999999999999999996747", tolerance);
737 Check (0xFFFFFFFFFFFFFFFBULL,
"+0.9999999999999999997289", tolerance);
738 Check (0xFFFFFFFFFFFFFFFCULL,
"+0.9999999999999999997832", tolerance);
739 Check (0xFFFFFFFFFFFFFFFDULL,
"+0.9999999999999999998374", tolerance);
740 Check (0xFFFFFFFFFFFFFFFEULL,
"+0.9999999999999999998916", tolerance);
741 Check (0xFFFFFFFFFFFFFFFFULL,
"+0.9999999999999999999458", tolerance);
749 virtual void DoRun (
void);
751 void Check (
const bool result,
const bool expect,
752 const std::string & msg);
755 :
TestCase (
"Basic compare operations")
759 const std::string & msg)
761 bool pass = result == expect;
764 << (pass ?
"pass " :
"FAIL ")
774 std::cout << std::endl;
789 Check ( zerof == zerof,
true,
"equality, zero");
790 Check ( onef == onef,
true,
"equality, positive");
791 Check ( mtwof == mtwof,
true,
"equality, negative");
792 Check (
zero == one,
false,
"equality false, zero");
793 Check ( one == two,
false,
"equality false, unsigned");
794 Check ( one == mone,
false,
"equality false, signed");
795 Check ( onef == one,
false,
"equality false, fraction");
796 std::cout << std::endl;
798 Check ( zerof != zerof,
false,
"inequality, zero");
799 Check ( onef != onef,
false,
"inequality, positive");
800 Check ( mtwof != mtwof,
false,
"inequality, negative");
801 Check (
zero != one,
true,
"inequality true, zero");
802 Check ( one != two,
true,
"inequality true, unsigned");
803 Check ( one != mone,
true,
"inequality true, signed");
804 Check ( onef != one,
true,
"inequality true, fraction");
805 std::cout << std::endl;
807 Check ( zerof < onef,
true,
"less, zerof");
808 Check (
zero < zerof,
true,
"less, zero");
809 Check ( one < onef,
true,
"less, positive");
810 Check ( monef < mone,
true,
"less, negative");
811 Check ( onef < one,
false,
"less, false, positive");
812 Check ( mtwo < mtwof,
false,
"less, false, negative");
813 std::cout << std::endl;
815 Check ( zerof <= zerof,
true,
"less equal, equal, zerof");
816 Check (
zero <= zerof,
true,
"less equal, less, zero");
817 Check ( onef <= onef,
true,
"less equal, equal, positive");
818 Check ( monef <= mone,
true,
"less equal, less, negative");
819 Check ( onef <= one,
false,
"less equal, false, positive");
820 Check ( mtwo <= mtwof,
false,
"less equal, false, negative");
821 std::cout << std::endl;
823 Check ( onef > zerof,
true,
"greater, zerof");
824 Check ( zerof >
zero,
true,
"greater, zero");
825 Check ( onef > one,
true,
"greater, positive");
826 Check ( mone > monef,
true,
"greater, negative");
827 Check ( one > onef,
false,
"greater, false, positive");
828 Check ( mtwof > mtwo,
false,
"greater, false, negative");
829 std::cout << std::endl;
831 Check ( zerof >= zerof,
true,
"greater equal, equal, zerof");
832 Check ( zerof >=
zero,
true,
"greater equal, greater, zero");
833 Check ( onef >= onef,
true,
"greater equal, equal, positive");
834 Check ( mone >= monef,
true,
"greater equal, greater, negative");
835 Check ( one >= onef,
false,
"greater equal, false, positive");
836 Check ( mtwof >= mtwo,
false,
"greater equal, false, negative");
837 std::cout << std::endl;
839 Check (
zero ==
false,
true,
"zero == false");
840 Check ( one ==
true,
true,
"one == true");
841 Check ( zerof !=
false,
true,
"zerof != false");
842 Check ( (!
zero) ==
true,
true,
"!zero == true");
843 Check ( (!zerof) ==
false,
true,
"!zerof == false");
844 Check ( (!one) ==
false,
true,
"!one == false");
845 Check ( (+onef) == onef,
true,
"unary positive");
846 Check ( (-onef) == monef,
true,
"unary negative");
854 virtual void DoRun (
void);
855 void Check (
const int64_t factor);
858 const std::string & msg,
859 const double tolerance = 0);
863 :
TestCase (
"Invert and MulByInvert")
869 const std::string & msg,
870 const double tolerance )
872 bool pass =
Abs (result - expect) <= tolerance;
878 std::cout <<
"pass: " << factor <<
": ";
883 std::cout <<
"FAIL: " << factor <<
": " 884 <<
"(res: " << result
885 <<
" exp: " << expect
886 <<
" tol: " << tolerance <<
") ";
903 double tolerance = 0;
907 tolerance = 0.000000000000000001L;
911 CheckCase (factor, b, one,
"x * x^-1 == 1", tolerance);
915 CheckCase (factor, c, factorI,
"1 * x^-1 == 1 / x");
923 CheckCase (factor, e, -one,
"-x * x^-1 == -1", tolerance);
929 std::cout << std::endl;
949 Check (10000000000LL);
950 Check (100000000000LL);
951 Check (1000000000000LL);
952 Check (10000000000000LL);
953 Check (100000000000000LL);
954 Check (1000000000000000LL);
962 virtual void DoRun (
void);
963 void Check (
const int64_t intPart);
964 void Check (
const long double value,
965 const int64_t intPart,
975 :
TestCase (
"Construct from floating point.")
980 const int64_t intPart,
992 long double margin = 0;
1010 const bool skip = value ==
m_last;
1011 const bool pass = delta <= tolerance;
1014 std::ios_base::fmtflags ff = std::cout.flags ();
1015 std::cout << std::fixed << std::setprecision (22);
1018 << (skip ?
"skip " : (pass ?
"pass " :
"FAIL "))
1019 << std::showpos << value <<
" == " 1027 << std::left << std::setw (43) <<
" expected" 1028 << std::right <<
Printer (expect)
1031 if (delta == tolerance)
1034 << std::left << std::setw (43) <<
" delta = tolerance" 1035 << std::right <<
Printer (delta)
1041 << std::left << std::setw (43) <<
" delta" 1042 << std::right <<
Printer (delta)
1045 << std::left << std::setw (43) <<
" +/-" 1046 << std::right <<
Printer (tolerance)
1059 "int64x64_t (long double) failed");
1061 std::cout.flags (ff);
1068 std::cout << std::endl;
1070 <<
"integer: " << intPart
1072 m_last =
static_cast<long double> (intPart);
1076 long double v =
static_cast<long double> (intPart);
1078 Check (v + 0.0000000000000000000542L, intPart, 0x1ULL);
1079 Check (v + 0.0000000000000000001084L, intPart, 0x2ULL);
1080 Check (v + 0.0000000000000000001626L, intPart, 0x3ULL);
1081 Check (v + 0.0000000000000000002168L, intPart, 0x4ULL);
1082 Check (v + 0.0000000000000000002710L, intPart, 0x5ULL);
1083 Check (v + 0.0000000000000000003253L, intPart, 0x6ULL);
1084 Check (v + 0.0000000000000000003795L, intPart, 0x7ULL);
1085 Check (v + 0.0000000000000000004337L, intPart, 0x8ULL);
1086 Check (v + 0.0000000000000000004879L, intPart, 0x9ULL);
1087 Check (v + 0.0000000000000000005421L, intPart, 0xAULL);
1088 Check (v + 0.0000000000000000008132L, intPart, 0xFULL);
1089 Check (v + 0.0000000000000000130104L, intPart, 0xF0ULL);
1090 Check (v + 0.0000000000000002081668L, intPart, 0xF00ULL);
1091 Check (v + 0.0000000000000033306691L, intPart, 0xF000ULL);
1092 Check (v + 0.0000000000000532907052L, intPart, 0xF0000ULL);
1093 Check (v + 0.0000000000008526512829L, intPart, 0xF00000ULL);
1094 Check (v + 0.0000000000136424205266L, intPart, 0xF000000ULL);
1095 Check (v + 0.0000000002182787284255L, intPart, 0xF0000000ULL);
1096 Check (v + 0.0000000034924596548080L, intPart, 0xF00000000ULL);
1097 Check (v + 0.0000000558793544769287L, intPart, 0xF000000000ULL);
1098 Check (v + 0.0000008940696716308594L, intPart, 0xF0000000000ULL);
1099 Check (v + 0.0000143051147460937500L, intPart, 0xF00000000000ULL);
1100 Check (v + 0.0002288818359375000000L, intPart, 0xF000000000000ULL);
1101 Check (v + 0.0036621093750000000000L, intPart, 0xF0000000000000ULL);
1102 Check (v + 0.0585937500000000000000L, intPart, 0xF00000000000000ULL);
1103 std::cout << std::endl;
1104 Check (v + 0.4999999999999999998374L, intPart, 0x7FFFFFFFFFFFFFFDULL);
1105 Check (v + 0.4999999999999999998916L, intPart, 0x7FFFFFFFFFFFFFFEULL);
1106 Check (v + 0.4999999999999999999458L, intPart, 0x7FFFFFFFFFFFFFFFULL);
1107 Check (v + 0.5000000000000000000000L, intPart, 0x8000000000000000ULL);
1108 Check (v + 0.5000000000000000000542L, intPart, 0x8000000000000001ULL);
1109 Check (v + 0.5000000000000000001084L, intPart, 0x8000000000000002ULL);
1110 Check (v + 0.5000000000000000001626L, intPart, 0x8000000000000003ULL);
1111 std::cout << std::endl;
1112 Check (v + 0.9375000000000000000000L, intPart, 0xF000000000000000ULL);
1113 Check (v + 0.9960937500000000000000L, intPart, 0xFF00000000000000ULL);
1114 Check (v + 0.9997558593750000000000L, intPart, 0xFFF0000000000000ULL);
1115 Check (v + 0.9999847412109375000000L, intPart, 0xFFFF000000000000ULL);
1116 Check (v + 0.9999990463256835937500L, intPart, 0xFFFFF00000000000ULL);
1117 Check (v + 0.9999999403953552246094L, intPart, 0xFFFFFF0000000000ULL);
1118 Check (v + 0.9999999962747097015381L, intPart, 0xFFFFFFF000000000ULL);
1119 Check (v + 0.9999999997671693563461L, intPart, 0xFFFFFFFF00000000ULL);
1120 Check (v + 0.9999999999854480847716L, intPart, 0xFFFFFFFFF0000000ULL);
1121 Check (v + 0.9999999999990905052982L, intPart, 0xFFFFFFFFFF000000ULL);
1122 Check (v + 0.9999999999999431565811L, intPart, 0xFFFFFFFFFFF00000ULL);
1123 Check (v + 0.9999999999999964472863L, intPart, 0xFFFFFFFFFFFF0000ULL);
1124 Check (v + 0.9999999999999997779554L, intPart, 0xFFFFFFFFFFFFF000ULL);
1125 Check (v + 0.9999999999999999861222L, intPart, 0xFFFFFFFFFFFFFF00ULL);
1126 Check (v + 0.9999999999999999991326L, intPart, 0xFFFFFFFFFFFFFFF0ULL);
1127 Check (v + 0.9999999999999999994037L, intPart, 0xFFFFFFFFFFFFFFF5ULL);
1128 Check (v + 0.9999999999999999994579L, intPart, 0xFFFFFFFFFFFFFFF6ULL);
1129 Check (v + 0.9999999999999999995121L, intPart, 0xFFFFFFFFFFFFFFF7ULL);
1130 Check (v + 0.9999999999999999995663L, intPart, 0xFFFFFFFFFFFFFFF8ULL);
1131 Check (v + 0.9999999999999999996205L, intPart, 0xFFFFFFFFFFFFFFF9ULL);
1132 Check (v + 0.9999999999999999996747L, intPart, 0xFFFFFFFFFFFFFFFAULL);
1133 Check (v + 0.9999999999999999997289L, intPart, 0xFFFFFFFFFFFFFFFBULL);
1134 Check (v + 0.9999999999999999997832L, intPart, 0xFFFFFFFFFFFFFFFCULL);
1135 Check (v + 0.9999999999999999998374L, intPart, 0xFFFFFFFFFFFFFFFDULL);
1136 Check (v + 0.9999999999999999998916L, intPart, 0xFFFFFFFFFFFFFFFEULL);
1137 Check (v + 0.9999999999999999999458L, intPart, 0xFFFFFFFFFFFFFFFFULL);
1140 <<
"integer: " << intPart
1149 std::cout << std::endl;
1154 std::ios_base::fmtflags ff = std::cout.flags ();
1155 std::cout << std::scientific << std::setprecision (21);
1172 std::cout.flags (ff);
1180 virtual void DoRun (
void);
1184 :
TestCase (
"Print the implementation")
1190 std::cout << std::endl;
1195 std::cout <<
"int64x64_t::implementation: ";
1202 default : std::cout <<
"unknown!";
1205 std::cout << std::endl;
1207 #if defined (INT64X64_USE_CAIRO) && !defined (PYTHON_SCAN) 1208 std::cout <<
"cairo_impl64: " <<
cairo_impl64 << std::endl;
1209 std::cout <<
"cairo_impl128: " <<
cairo_impl128 << std::endl;
1214 std::cout <<
"Running with valgrind" << std::endl;
Pretty printer for test cases.
virtual void DoRun(void)
Implementation to actually run this TestCase.
ns3::int64x64::test::Int64x64TestSuite g_int64x64TestSuite
std::ostream & operator<<(std::ostream &os, const Printer &p)
Int64x64Bug1786TestCase()
High precision numerical type, implementing Q64.64 fixed precision.
bool m_haveInt
Do we have a full int64x64_t value?
void CheckCase(const uint64_t factor, const int64x64_t result, const int64x64_t expect, const std::string &msg, const double tolerance=0)
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 int64_t factor)
void Check(const bool result, const bool expect, const std::string &msg)
const char * cairo_impl128
static int64x64_t Invert(const uint64_t v)
Compute the inverse of an integer value.
void Check(const int64_t intPart)
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define RUNNING_ON_VALGRIND
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
Printer(const int64x64_t value)
Construct from an int64x64_t Q64.64 value.
int64_t m_high
The high (integer) word.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
uint64_t m_low
The low (fractional) word.
void Check(const int test, const int64x64_t value, const int64x64_t expect)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
friend std::ostream & operator<<(std::ostream &os, const Printer &p)
Output streamer, the main reason for this class.
virtual void DoRun(void)
Implementation to actually run this TestCase.
int64x64_t m_value
The int64x64_t 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.
void Check(const int64_t hi, const uint64_t lo)
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
#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 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 ...
int64x64_t Abs(const int64x64_t &value)
Absolute value.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoRun(void)
Implementation to actually run this TestCase.
TestCase * GetParent() const
Get the parent of this TestCsse.
const char * cairo_impl64
#define HP_MAX_64
Floating point value of HP_MASK_LO + 1.
std::string GetName(void) const
Native int128_t implementation.
uint64_t GetLow(void) const
Get the fractional portion of this value, unscaled.
Cairo wideint implementation.
Printer(const int64_t high, const uint64_t low)
Construct from high and low words of Q64.64 representation.
double GetDouble(void) const
Get this value as a double.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const double result, const double expect, const std::string &msg)
Int64x64ArithmeticTestCase()
This test suite implements a Unit Test.
void Check(const uint64_t low, const std::string &value, const int64_t tolerance=0)
Int64x64CompareTestCase()
long double implementation.
int64_t GetHigh(void) const
Get the integer portion.
static enum impl_type implementation
Type tag for this implementation.