8#ifndef LIBFXD_CONSTRUCTORS_HPP
9#define LIBFXD_CONSTRUCTORS_HPP
18#include "detail/bias.hpp"
19#include "detail/opacify.hpp"
20#include "detail/shift.hpp"
33 template<std::
integral I>
39 if constexpr (frac_bits < 0) {
44 i += detail::make_bias_for(-frac_bits, i);
46 raw_value = detail::shr_real(i, -frac_bits);
52 using IWide = detail::max_int_for<raw_type>;
53 raw_value = detail::shl_real<IWide>(i, frac_bits);
64 template<std::
floating_po
int Flt>
69 const auto scaled_f = std::ldexp(f, frac_bits);
70 raw_value =
static_cast<raw_type>(scaled_f);
75 template<
int Int,
int Frac,
typename Raw>
76 template<
int Int2,
int Frac2,
typename Raw2>
77 requires (detail::is_safe_conversion_v<Int2, Frac2, Raw2,
82 raw_value{fixed_cast<fixed<Int, Frac, Raw>>(other).raw_value}
101 result.
raw_value =
static_cast<Raw
>(val);
This is the namespace where the entire library is defined.
The fixed-point class template.
constexpr fixed() noexcept=default
Defaulted constructor.
static constexpr fixed from_raw(raw_type val) noexcept
Constructs a fixed from any raw bit representation (no conversion.)
Raw raw_type
The integral type that will hold the raw representation of the value.
raw_type raw_value
The raw value, stored as a bitfield.