8#ifndef LIBFXD_CASTING_HPP
9#define LIBFXD_CASTING_HPP
15#include "detail/bias.hpp"
16#include "detail/shift.hpp"
31 using SrcRaw =
typename Src::raw_type;
32 using DstRaw =
typename Dst::raw_type;
34 SrcRaw src_raw = src.raw_value;
37 constexpr int diff = Dst::frac_bits - Src::frac_bits;
39 if constexpr (diff < 0) {
43 src_raw += detail::make_bias_for(-diff, src_raw);
46 dst_raw = detail::shr_real(src_raw, -diff);
52 dst_raw = detail::shl_real<DstRaw>(src_raw, diff);
56 return Dst::from_raw(dst_raw);
63 typename Raw = detail::select_int_t<Int + Frac>,
71 return fixed_cast<fixed<Int, Frac, Raw>>(src);
78 typename Raw = detail::select_uint_t<Int + Frac>,
86 return fixed_cast<fixed<Int, Frac, Raw>>(src);
Concept to match any fxd::fixed
This is the namespace where the entire library is defined.
constexpr Dst fixed_cast(Src src) noexcept
Convert a fixed point to a different type of fixed point.
constexpr fixed< Int, Frac, Raw > ufixed_cast(Src src) noexcept
Convert a fixed point to a different type of fixed point (unsigned version.)