15 TEST(f1.
value() == 0);
17 TEST(f2.value() == 10000);
19 TEST(f3.value() == 31416);
20 fixed f4(2, 14159265);
21 TEST(f4.value() == 21416);
22 TEST(f2 + f4 == f1 + f3);
23 TEST(f2 + f4 <= f1 + f3);
24 TEST(f2 + f4 >= f1 + f3);
32 TEST(f2 + f4 == f3 - f1);
63 TEST(f4.as_string() ==
"3.1416");
64 TEST(f4.integer() == 3);
67 TEST(f4.integer() == 3);
68 TEST(f4.round() == 4);
70 TEST(f3.integer() == 3);
71 TEST((-f3).integer() == -3);
72 TEST(f3.fraction() == 1416);
73 TEST((-f3).fraction() == 1416);
75 TEST(
fixed(7,4999).round() == 7);
76 TEST(
fixed(7,5000).round() == 8);
77 TEST(
fixed(7,5001).round() == 8);
78 TEST(
fixed(7,4999).round() == 7);
79 TEST(
fixed(8,5000).round() == 8);
80 TEST(
fixed(8,5001).round() == 9);
91 TEST(
fixed(-7,4999).round() == -7);
92 TEST(
fixed(-7,5000).round() == -8);
93 TEST(
fixed(-7,5001).round() == -8);
94 TEST(
fixed(-7,4999).round() == -7);
95 TEST(
fixed(-8,5000).round() == -8);
96 TEST(
fixed(-8,5001).round() == -9);
98 TEST(
fixed(-3.14159265).value() == -31416);
99 TEST(
fixed(123,456789).value() == 1234568);
100 TEST(
fixed(123,4).value() == 1230004);
101 TEST(
fixed(-10,1111).value() == -101111);
103 std::ostringstream out;
104 out << f3 <<
" 3.14159265 " <<
fixed(-10,12) <<
" 3 421.4 end";
106 std::istringstream in(out.str());
112 TEST(f5.
value() == -100012);
114 TEST(f5.
value() == 30000);
116 TEST(f5.
value() == 4214000);
117 TEST(not (in >> f5));
125 }
catch (std::invalid_argument
const& ex) {
Implement a fixed-point number class. Values have places places after the decimal point...
value_type value() const
Return the internal value.