Fixed-point decimal data type and related functions.
Classes | |
| class | CeilingRoundPolicy |
| Round towards +infinity. More... | |
| class | Decimal |
| Fixed-point decimal data type for use in deterministic calculations, oftentimes involving money. More... | |
| class | DecimalError |
| The base class for Decimal-related exceptions. More... | |
| class | DefRoundPolicy |
| Default rounding. Fast, rounds to nearest. More... | |
| class | DivisionByZeroError |
Thrown on division by zero in Decimal arithmetic. More... | |
| class | FloorRoundPolicy |
| Round towards -infinity. More... | |
| struct | FormatOptions |
| Parameters for flexible decimal formatting. More... | |
| class | HalfDownRoundPolicy |
| Round to nearest, 0.5 towards zero. More... | |
| class | HalfEvenRoundPolicy |
| Round to nearest, 0.5 towards number with even last digit. More... | |
| class | HalfUpRoundPolicy |
| Round to nearest, 0.5 away from zero. More... | |
| class | OutOfBoundsError |
Thrown on overflow in Decimal arithmetic. More... | |
| class | ParseError |
Thrown on all errors related to parsing Decimal from string. More... | |
| class | RoundDownRoundPolicy |
| Round towards zero. The fastest rounding. More... | |
| class | RoundUpRoundPolicy |
| Round away from zero. More... | |
Functions | |
| constexpr int64_t | Pow10 (int exp) |
| A fast, constexpr-friendly power of 10. | |
| template<typename T, int OldPrec, typename OldRound> | |
| constexpr T | decimal_cast (Decimal< OldPrec, OldRound > arg) |
Cast one Decimal to another Decimal type. | |
| template<int Prec, typename RoundPolicy> | |
| std::string | ToString (Decimal< Prec, RoundPolicy > dec) |
| Converts Decimal to a string. | |
| template<int Prec, typename RoundPolicy> | |
| std::string | ToString (const Decimal< Prec, RoundPolicy > &dec, const FormatOptions &format_options) |
| Converts Decimal to a string. | |
| template<int Prec, typename RoundPolicy> | |
| std::string | ToStringTrailingZeros (Decimal< Prec, RoundPolicy > dec) |
Converts Decimal to a string, writing exactly Prec decimal digits. | |
| template<int NewPrec, int Prec, typename RoundPolicy> | |
| std::string | ToStringFixed (Decimal< Prec, RoundPolicy > dec) |
Converts Decimal to a string with exactly NewPrec decimal digits. | |
| template<typename CharT, typename Traits, int Prec, typename RoundPolicy> | |
| std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &is, Decimal< Prec, RoundPolicy > &d) |
Parses a Decimal from the istream | |
| template<typename CharT, typename Traits, int Prec, typename RoundPolicy> | |
| std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const Decimal< Prec, RoundPolicy > &d) |
Writes the Decimal to the ostream | |
| template<int Prec, typename RoundPolicy> | |
| logging::LogHelper & | operator<< (logging::LogHelper &lh, const Decimal< Prec, RoundPolicy > &d) |
Writes the Decimal to the logger. | |
| template<int Prec, typename RoundPolicy, formats::common::kIsFormatValue Value> | |
| Decimal< Prec, RoundPolicy > | Parse (const Value &value, formats::parse::To< Decimal< Prec, RoundPolicy > >) |
Parses the Decimal from the string. | |
| template<int Prec, typename RoundPolicy, typename TargetType> | |
| TargetType | Serialize (const Decimal< Prec, RoundPolicy > &object, formats::serialize::To< TargetType >) |
Serializes the Decimal to string. | |
| template<int Prec, typename RoundPolicy, typename StringBuilder> | |
| void | WriteToStream (const Decimal< Prec, RoundPolicy > &object, StringBuilder &sw) |
Writes the Decimal to stream. | |
| template<int Prec, typename RoundPolicy> | |
| void | PrintTo (const Decimal< Prec, RoundPolicy > &v, std::ostream *os) |
| gtest formatter for decimal64::Decimal | |
Variables | |
| template<int Exp> | |
| constexpr int64_t | kPow10 = Pow10(Exp) |
| A guaranteed-compile-time power of 10. | |
|
constexpr |
Cast one Decimal to another Decimal type.
When casting to a Decimal with a lower Prec, rounding is performed according to the new RoundPolicy.
Usage example:
Definition at line 825 of file decimal64.hpp.
| logging::LogHelper & decimal64::operator<< | ( | logging::LogHelper & | lh, |
| const Decimal< Prec, RoundPolicy > & | d ) |
| std::basic_ostream< CharT, Traits > & decimal64::operator<< | ( | std::basic_ostream< CharT, Traits > & | os, |
| const Decimal< Prec, RoundPolicy > & | d ) |
| std::basic_istream< CharT, Traits > & decimal64::operator>> | ( | std::basic_istream< CharT, Traits > & | is, |
| Decimal< Prec, RoundPolicy > & | d ) |
Parses a Decimal from the istream
Acts like the Decimal(str) constructor, except that it allows junk that immediately follows the number and supports exponential format. Sets the stream's fail bit on failure.
Usage example:
if (os >> dec) {
// success
} else {
// failure
}
Definition at line 1553 of file decimal64.hpp.
| Decimal< Prec, RoundPolicy > decimal64::Parse | ( | const Value & | value, |
| formats::parse::To< Decimal< Prec, RoundPolicy > > | ) |
Parses the Decimal from the string.
Definition at line 1592 of file decimal64.hpp.
|
constexpr |
A fast, constexpr-friendly power of 10.
Definition at line 305 of file decimal64.hpp.
| void decimal64::PrintTo | ( | const Decimal< Prec, RoundPolicy > & | v, |
| std::ostream * | os ) |
gtest formatter for decimal64::Decimal
Definition at line 1620 of file decimal64.hpp.
| TargetType decimal64::Serialize | ( | const Decimal< Prec, RoundPolicy > & | object, |
| formats::serialize::To< TargetType > | ) |
| std::string decimal64::ToString | ( | const Decimal< Prec, RoundPolicy > & | dec, |
| const FormatOptions & | format_options ) |
Converts Decimal to a string.
Usage example:
ToString(decimal64::Decimal<4>{"-1234.1234"},
{"||", "**", "\1", "<>", {}, true})) -> "<>1**2**3**4||1234"
ToString(decimal64::Decimal<4>{"-1234.1234"},
{",", " ", "\3", "-", 6, true})) -> "-1 234,123400"
Definition at line 1502 of file decimal64.hpp.
| std::string decimal64::ToString | ( | Decimal< Prec, RoundPolicy > | dec | ) |
Converts Decimal to a string.
Usage example:
ToString(decimal64::Decimal<4>{"1.5"}) -> 1.5
Definition at line 1486 of file decimal64.hpp.
| std::string decimal64::ToStringFixed | ( | Decimal< Prec, RoundPolicy > | dec | ) |
Converts Decimal to a string with exactly NewPrec decimal digits.
Usage example:
ToStringFixed<3>(decimal64::Decimal<4>{"1.5"}) -> 1.500
Definition at line 1533 of file decimal64.hpp.
| std::string decimal64::ToStringTrailingZeros | ( | Decimal< Prec, RoundPolicy > | dec | ) |
Converts Decimal to a string, writing exactly Prec decimal digits.
Usage example:
ToStringTrailingZeros(decimal64::Decimal<4>{"1.5"}) -> 1.5000
Definition at line 1520 of file decimal64.hpp.
| void decimal64::WriteToStream | ( | const Decimal< Prec, RoundPolicy > & | object, |
| StringBuilder & | sw ) |
|
inlineconstexpr |
A guaranteed-compile-time power of 10.
Definition at line 314 of file decimal64.hpp.