userver: userver/decimal64/decimal64.hpp File Reference
Loading...
Searching...
No Matches
decimal64.hpp File Reference

Detailed Description

Decimal data type for fixed-point arithmetic.

Definition in file decimal64.hpp.

Go to the source code of this file.

#include <array>
#include <cassert>
#include <cstdint>
#include <ios>
#include <iosfwd>
#include <istream>
#include <limits>
#include <numeric>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <fmt/compile.h>
#include <fmt/format.h>
#include <userver/decimal64/format_options.hpp>
#include <userver/formats/common/meta.hpp>
#include <userver/utils/assert.hpp>
#include <userver/utils/flags.hpp>
#include <userver/utils/meta_light.hpp>
+ Include dependency graph for decimal64.hpp:
+ This graph shows which files directly or indirectly include this file:

Classes

class  decimal64::DecimalError
 The base class for Decimal-related exceptions. More...
 
class  decimal64::ParseError
 Thrown on all errors related to parsing Decimal from string. More...
 
class  decimal64::OutOfBoundsError
 Thrown on overflow in Decimal arithmetic. More...
 
class  decimal64::DivisionByZeroError
 Thrown on division by zero in Decimal arithmetic. More...
 
class  decimal64::DefRoundPolicy
 Default rounding. Fast, rounds to nearest. More...
 
class  decimal64::HalfDownRoundPolicy
 Round to nearest, 0.5 towards zero. More...
 
class  decimal64::HalfUpRoundPolicy
 Round to nearest, 0.5 away from zero. More...
 
class  decimal64::HalfEvenRoundPolicy
 Round to nearest, 0.5 towards number with even last digit. More...
 
class  decimal64::CeilingRoundPolicy
 Round towards +infinity. More...
 
class  decimal64::FloorRoundPolicy
 Round towards -infinity. More...
 
class  decimal64::RoundDownRoundPolicy
 Round towards zero. The fastest rounding. More...
 
class  decimal64::RoundUpRoundPolicy
 Round away from zero. More...
 
class  decimal64::Decimal< Prec, RoundPolicy_ >
 Fixed-point decimal data type for use in deterministic calculations, oftentimes involving money. More...
 
struct  std::hash<::decimal64::Decimal< Prec, RoundPolicy > >
 std::hash support More...
 
class  fmt::formatter<::decimal64::Decimal< Prec, RoundPolicy >, Char >
 fmt support More...
 

Namespaces

namespace  logging
 Logging macro and utilities.
 
namespace  decimal64
 Fixed-point decimal data type and related functions.
 

Functions

constexpr int64_t decimal64::Pow10 (int exp)
 A fast, constexpr-friendly power of 10.
 
template<typename T , int OldPrec, typename OldRound >
constexpr T decimal64::decimal_cast (Decimal< OldPrec, OldRound > arg)
 Cast one Decimal to another Decimal type.
 
template<int Prec, typename RoundPolicy >
std::string decimal64::ToString (Decimal< Prec, RoundPolicy > dec)
 Converts Decimal to a string.
 
template<int Prec, typename RoundPolicy >
std::string decimal64::ToString (const Decimal< Prec, RoundPolicy > &dec, const FormatOptions &format_options)
 Converts Decimal to a string.
 
template<int Prec, typename RoundPolicy >
std::string decimal64::ToStringTrailingZeros (Decimal< Prec, RoundPolicy > dec)
 Converts Decimal to a string, writing exactly Prec decimal digits.
 
template<int NewPrec, int Prec, typename RoundPolicy >
std::string decimal64::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 > & decimal64::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 > & decimal64::operator<< (std::basic_ostream< CharT, Traits > &os, const Decimal< Prec, RoundPolicy > &d)
 Writes the Decimal to the ostream
 
template<int Prec, typename RoundPolicy >
logging::LogHelperdecimal64::operator<< (logging::LogHelper &lh, const Decimal< Prec, RoundPolicy > &d)
 Writes the Decimal to the logger.
 
template<int Prec, typename RoundPolicy , typename Value >
std::enable_if_t< formats::common::kIsFormatValue< Value >, Decimal< Prec, RoundPolicy > > decimal64::Parse (const Value &value, formats::parse::To< Decimal< Prec, RoundPolicy > >)
 Parses the Decimal from the string.
 
template<int Prec, typename RoundPolicy , typename TargetType >
TargetType decimal64::Serialize (const Decimal< Prec, RoundPolicy > &object, formats::serialize::To< TargetType >)
 Serializes the Decimal to string.
 
template<int Prec, typename RoundPolicy , typename StringBuilder >
void decimal64::WriteToStream (const Decimal< Prec, RoundPolicy > &object, StringBuilder &sw)
 Writes the Decimal to stream.
 

Variables

template<int Exp>
constexpr int64_t decimal64::kPow10 = Pow10(Exp)
 A guaranteed-compile-time power of 10.
 
template<typename T >
constexpr bool decimal64::kIsDecimal = impl::IsDecimal<T>::value
 true if the type is an instantiation of Decimal