FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::Fixed< Tag > Struct Template Reference

#include <fastmm/core/fixed_point.hpp>

Public Types

using rep_type = std::int64_t
 

Public Member Functions

constexpr Fixed () noexcept=default
 
double to_bps () const noexcept
 Ratio only. Diagnostics only.
 
std::size_t to_decimal (char *buf) const noexcept
 Formats into buf (>= kMaxDecimalChars), trims trailing zeros ("1.5", "100", "0.00000001").
 
double to_double () const noexcept
 
constexpr bool is_zero () const noexcept
 
constexpr bool is_positive () const noexcept
 
constexpr bool is_negative () const noexcept
 
constexpr Fixed abs () const noexcept
 
constexpr std::int64_t units () const noexcept
 
constexpr auto operator<=> (const Fixed &) const noexcept=default
 
constexpr Fixed operator- () const noexcept
 
constexpr Fixed & operator+= (Fixed o) noexcept
 
constexpr Fixed & operator-= (Fixed o) noexcept
 
constexpr Fixed & operator*= (std::int64_t k) noexcept
 

Static Public Member Functions

static constexpr Fixed from_raw (std::int64_t r) noexcept
 
static constexpr Fixed from_int (std::int64_t units) noexcept
 Whole units, e.g. from_int(100) == 100.00000000.
 
static constexpr Fixed zero () noexcept
 
static constexpr Fixed max () noexcept
 
static constexpr Fixed min () noexcept
 
static constexpr std::optional< Fixed > from_decimal (std::string_view s) noexcept
 Exact parse of "[+-]digits[.digits]".
 
static constexpr std::optional< Fixed > parse (std::string_view s) noexcept
 Exact parse of a decimal in plain or exponent notation: "0.1", "2e-05", "1.5E3", "-3".
 
static Fixed from_bps (double bps) noexcept
 Ratio only.
 
static std::optional< Fixed > from_bps_checked (double bps) noexcept
 
static Fixed from_double (double d) noexcept
 Rounds to the 1e-8 grid.
 
static std::optional< Fixed > from_double_checked (double d) noexcept
 nullopt for NaN, +-inf and anything outside the representable range; two compares more.
 

Public Attributes

std::int64_t raw = 0
 

Friends

constexpr Fixed operator+ (Fixed a, Fixed b) noexcept
 
constexpr Fixed operator- (Fixed a, Fixed b) noexcept
 
constexpr Fixed operator* (Fixed a, std::int64_t k) noexcept
 
constexpr Fixed operator* (std::int64_t k, Fixed a) noexcept
 
constexpr Fixed operator/ (Fixed a, std::int64_t k) noexcept
 
constexpr std::int64_t operator/ (Fixed a, Fixed b) noexcept
 Number of whole ticks in a (truncating); result is a plain integer.
 
constexpr Fixed operator% (Fixed a, Fixed b) noexcept
 

Member Typedef Documentation

◆ rep_type

template<class Tag >
using fastmm::Fixed< Tag >::rep_type = std::int64_t

Constructor & Destructor Documentation

◆ Fixed()

template<class Tag >
constexpr fastmm::Fixed< Tag >::Fixed ( )
constexprdefaultnoexcept

Member Function Documentation

◆ from_raw()

template<class Tag >
static constexpr Fixed fastmm::Fixed< Tag >::from_raw ( std::int64_t  r)
inlinestaticconstexprnoexcept

◆ from_int()

template<class Tag >
static constexpr Fixed fastmm::Fixed< Tag >::from_int ( std::int64_t  units)
inlinestaticconstexprnoexcept

Whole units, e.g. from_int(100) == 100.00000000.

◆ zero()

template<class Tag >
static constexpr Fixed fastmm::Fixed< Tag >::zero ( )
inlinestaticconstexprnoexcept

◆ max()

template<class Tag >
static constexpr Fixed fastmm::Fixed< Tag >::max ( )
inlinestaticconstexprnoexcept

◆ min()

template<class Tag >
static constexpr Fixed fastmm::Fixed< Tag >::min ( )
inlinestaticconstexprnoexcept

◆ from_decimal()

template<class Tag >
static constexpr std::optional< Fixed > fastmm::Fixed< Tag >::from_decimal ( std::string_view  s)
inlinestaticconstexprnoexcept

Exact parse of "[+-]digits[.digits]".

Rejects: empty, >8 significant fraction digits, integer overflow, exponents, whitespace. Trailing zeros beyond 8 places are accepted.

< 92233720368

< s[i] == '.'

< would lose precision

◆ parse()

template<class Tag >
static constexpr std::optional< Fixed > fastmm::Fixed< Tag >::parse ( std::string_view  s)
inlinestaticconstexprnoexcept

Exact parse of a decimal in plain or exponent notation: "0.1", "2e-05", "1.5E3", "-3".

Used for configuration values (TOML floats arrive formatted by fmt, Python floats by repr). Rejects a value only if more than 8 decimals remain after applying the exponent, or it is out of range. Venue strings use the stricter from_decimal.

◆ from_bps()

template<class Tag >
static Fixed fastmm::Fixed< Tag >::from_bps ( double  bps)
inlinestaticnoexcept

Ratio only.

Startup only (double): Ratio::from_bps(2.5) == 2.5 bps, rounded to 0.0001 bp. Saturates like from_double; from_bps_checked() reports the loss instead.

◆ from_bps_checked()

template<class Tag >
static std::optional< Fixed > fastmm::Fixed< Tag >::from_bps_checked ( double  bps)
inlinestaticnoexcept

◆ to_bps()

template<class Tag >
double fastmm::Fixed< Tag >::to_bps ( ) const
inlinenoexcept

Ratio only. Diagnostics only.

◆ to_decimal()

template<class Tag >
std::size_t fastmm::Fixed< Tag >::to_decimal ( char *  buf) const
inlinenoexcept

Formats into buf (>= kMaxDecimalChars), trims trailing zeros ("1.5", "100", "0.00000001").

Returns the number of chars written; no NUL is appended.

integer part

◆ from_double()

template<class Tag >
static Fixed fastmm::Fixed< Tag >::from_double ( double  d)
inlinestaticnoexcept

Rounds to the 1e-8 grid.

NaN becomes zero and a value outside +-92,233,720,368.54775807 saturates at max()/min(); the unchecked cast this replaced made both INT64_MIN.

◆ from_double_checked()

template<class Tag >
static std::optional< Fixed > fastmm::Fixed< Tag >::from_double_checked ( double  d)
inlinestaticnoexcept

nullopt for NaN, +-inf and anything outside the representable range; two compares more.

◆ to_double()

template<class Tag >
double fastmm::Fixed< Tag >::to_double ( ) const
inlinenoexcept

◆ is_zero()

template<class Tag >
constexpr bool fastmm::Fixed< Tag >::is_zero ( ) const
inlineconstexprnoexcept

◆ is_positive()

template<class Tag >
constexpr bool fastmm::Fixed< Tag >::is_positive ( ) const
inlineconstexprnoexcept

◆ is_negative()

template<class Tag >
constexpr bool fastmm::Fixed< Tag >::is_negative ( ) const
inlineconstexprnoexcept

◆ abs()

template<class Tag >
constexpr Fixed fastmm::Fixed< Tag >::abs ( ) const
inlineconstexprnoexcept

◆ units()

template<class Tag >
constexpr std::int64_t fastmm::Fixed< Tag >::units ( ) const
inlineconstexprnoexcept

◆ operator<=>()

template<class Tag >
constexpr auto fastmm::Fixed< Tag >::operator<=> ( const Fixed< Tag > &  ) const
constexprdefaultnoexcept

◆ operator-()

template<class Tag >
constexpr Fixed fastmm::Fixed< Tag >::operator- ( ) const
inlineconstexprnoexcept

◆ operator+=()

template<class Tag >
constexpr Fixed & fastmm::Fixed< Tag >::operator+= ( Fixed< Tag >  o)
inlineconstexprnoexcept

◆ operator-=()

template<class Tag >
constexpr Fixed & fastmm::Fixed< Tag >::operator-= ( Fixed< Tag >  o)
inlineconstexprnoexcept

◆ operator*=()

template<class Tag >
constexpr Fixed & fastmm::Fixed< Tag >::operator*= ( std::int64_t  k)
inlineconstexprnoexcept

Friends And Related Symbol Documentation

◆ operator+

template<class Tag >
constexpr Fixed operator+ ( Fixed< Tag >  a,
Fixed< Tag >  b 
)
friend

◆ operator-

template<class Tag >
constexpr Fixed operator- ( Fixed< Tag >  a,
Fixed< Tag >  b 
)
friend

◆ operator* [1/2]

template<class Tag >
constexpr Fixed operator* ( Fixed< Tag >  a,
std::int64_t  k 
)
friend

◆ operator* [2/2]

template<class Tag >
constexpr Fixed operator* ( std::int64_t  k,
Fixed< Tag >  a 
)
friend

◆ operator/ [1/2]

template<class Tag >
constexpr Fixed operator/ ( Fixed< Tag >  a,
std::int64_t  k 
)
friend

◆ operator/ [2/2]

template<class Tag >
constexpr std::int64_t operator/ ( Fixed< Tag >  a,
Fixed< Tag >  b 
)
friend

Number of whole ticks in a (truncating); result is a plain integer.

◆ operator%

template<class Tag >
constexpr Fixed operator% ( Fixed< Tag >  a,
Fixed< Tag >  b 
)
friend

Member Data Documentation

◆ raw

template<class Tag >
std::int64_t fastmm::Fixed< Tag >::raw = 0