17 throw std::invalid_argument(
"negative fraction not allowed");
18 fraction = reduce(fraction);
50 while (f >=
places10*10 and f % 10 == 0)
108 int adjust{
value() < 0 ? -1 : +1};
123 std::ostringstream out{};
198 strm.unsetf(std::ios_base::skipws);
199 if (not (strm >> decimal) or decimal !=
'.')
205 strm.clear(strm.rdstate() & ~strm.failbit);
216 p !=
places+1 and strm >> c and std::isdigit(c, strm.getloc());
226 while (strm and std::isdigit(c, strm.getloc()))
233 strm.clear(strm.rdstate() & ~strm.failbit);
245 if (not f.
read(strm))
246 strm.setstate(strm.failbit);
fixed & operator*=(fixed f)
Multiplication assignment operator.
Implement a fixed-point number class. Values have places places after the decimal point...
fixed operator*(fixed a, fixed b)
Multiply fixed values.
std::string as_string() const
bool operator>=(fixed a, fixed b)
Compare fixed values for greater-than-or-equal by comparing the underlying values.
bool operator<=(fixed a, fixed b)
Compare fixed values for less-than-or-equal by comparing the underlying values.
bool operator<(fixed a, fixed b)
Compare fixed values for less-than by comparing the underlying values.
value_type value() const
Return the internal value.
value_type integer() const
Return the integer part (which is the same as trunc()).
Save and restore I/O stream flags.
std::ostream & operator<<(std::ostream &strm, fixed f)
Write a fixed value.
value_type fraction() const
Return the fractional part, e.g., 3 for 12.03.
bool operator!=(fixed a, fixed b)
Compare fixed values for inequality by comparing the underlying values.
static int const places
number of decimal places
bool operator>(fixed a, fixed b)
Compare fixed values for greater-than by comparing the underlying values.
fixed & operator++()
Pre-increment.
fixed & operator+=(fixed f)
Addition assignment operator.
fixed & operator/=(fixed f)
Division assignment operator.
fixed & operator--()
Pre-decrement.
fixed operator/(fixed a, fixed b)
Divide fixed values.
void negate()
Negate this value.
fixed & operator-=(fixed f)
Subtraction assignment operator.
std::istream & operator>>(std::istream &strm, fixed &f)
Read a fixed value.
bool operator==(fixed a, fixed b)
Compare fixed values for equality by comparing the underlying values.
static value_type const places10
10places
fixed operator-(fixed a, fixed b)
Subtract fixed values.
int value_type
Type of the actual value.
fixed operator+(fixed a, fixed b)
Add fixed values.
fixed()
Default constructor initializes to zero.
bool read(std::istream &strm)