libfxd 0.2.dev
A fixed-point library for C++.
|
The fixed-point class template. More...
#include <fixed.hpp>
Public Types | |
using | raw_type = Raw |
The integral type that will hold the raw representation of the value. | |
Public Member Functions | |
constexpr | fixed () noexcept=default |
Defaulted constructor. | |
template<std::integral I> | |
constexpr | fixed (I i) noexcept |
Conversion from integer. | |
template<std::floating_point Flt> | |
constexpr | fixed (Flt f) noexcept |
Conversion from floating-point. | |
template<int Int2, int Frac2, typename Raw2 > requires (detail::is_safe_conversion_v<Int2, Frac2, Raw2, Int, Frac, Raw>) | |
constexpr | fixed (const fixed< Int2, Frac2, Raw2 > &other) noexcept |
Conversion from another fixed-point. | |
constexpr | operator bool () const noexcept |
Check if non-zero. | |
template<std::integral I> | |
constexpr | operator I () const noexcept |
Conversion to integer. | |
template<std::floating_point F> | |
constexpr | operator F () const noexcept |
Conversion to floating-point. | |
template<int Int2, int Frac2, typename Raw2 > | |
constexpr | operator fixed< Int2, Frac2, Raw2 > () const noexcept |
Conversion to another fixed-point. | |
Static Public Member Functions | |
static constexpr fixed | from_raw (raw_type val) noexcept |
Constructs a fixed from any raw bit representation (no conversion.) | |
Public Attributes | |
raw_type | raw_value: bits |
The raw value, stored as a bitfield. | |
Static Public Attributes | |
static constexpr int | int_bits = Int |
How many integral bits were requested. | |
static constexpr int | frac_bits = Frac |
How many fractional bits were requested. | |
static constexpr int | bits = int_bits + frac_bits |
How many bits were requested in total. | |
static constexpr int | raw_bits |
How many bits are used for storage (can be larger than bits ). | |
The fixed-point class template.
This class encapsulates an integer so it supports the arithmetic operations. It mimics floating-point types, but direct access to the internal integer can be done through the .raw_value
member variable.
Int | How many integral bits to use. |
Frac | How many fractional bits to use. |
Raw | The integral type that will be used to store the value. By default, it's a signed integer with at least Int + Frac bits. |
ufixed
. using raw_type = Raw |
|
constexprdefaultnoexcept |
Defaulted constructor.
|
constexprnoexcept |
Conversion from integer.
The i
value will be shifted (and rounded to zero, if negative) if needed.
Definition at line 36 of file constructors.hpp.
|
constexprnoexcept |
Conversion from floating-point.
Definition at line 66 of file constructors.hpp.
Conversion from another fixed-point.
Definition at line 80 of file constructors.hpp.
Constructs a fixed
from any raw bit representation (no conversion.)
All excess bits of val
will be truncated. Use this when you know the exact bit representation needed for the fixed
object.
Definition at line 97 of file constructors.hpp.
|
explicitconstexprnoexcept |
Check if non-zero.
Definition at line 32 of file conversions.hpp.
|
explicitconstexprnoexcept |
Conversion to floating-point.
Definition at line 125 of file conversions.hpp.
|
explicitconstexprnoexcept |
Conversion to another fixed-point.
Definition at line 136 of file conversions.hpp.
|
explicitconstexprnoexcept |
Conversion to integer.
Definition at line 86 of file conversions.hpp.
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
raw_type raw_value |