8#ifndef LIBFXD_ROUND_MUL_HPP
9#define LIBFXD_ROUND_MUL_HPP
13#include "detail/add.hpp"
14#include "detail/raw-mul.hpp"
15#include "detail/shift.hpp"
23 template<fixed_po
int Fxd>
30 constexpr int w = detail::type_width<typename Fxd::raw_type>;
33 constexpr int offset = w - Fxd::frac_bits;
35 const auto raw_a = a.raw_value;
36 const auto raw_b = b.raw_value;
37 const auto c = detail::raw::mul<Fxd::bits>(raw_a, raw_b);
39 if constexpr (Fxd::frac_bits <= 0) {
42 const auto d = detail::shl(c, offset);
43 return Fxd::from_raw(detail::high(d));
48 if (detail::is_negative(c)) {
51 const auto bias = detail::make_bias_for(Fxd::frac_bits, c);
52 const auto biased_c = detail::add(c, bias);
53 const auto d = detail::shl(biased_c, offset);
54 return Fxd::from_raw(detail::high(d));
58 const auto d = detail::shl(c, offset);
59 return Fxd::from_raw(detail::high(d));
74 template<fixed_po
int Fxd>
81 constexpr int w = detail::type_width<typename Fxd::raw_type>;
84 constexpr int offset = w - Fxd::frac_bits;
86 const auto raw_a = a.raw_value;
87 const auto raw_b = b.raw_value;
88 const auto c = detail::raw::mul<Fxd::bits>(raw_a, raw_b);
90 if constexpr (Fxd::frac_bits <= 0) {
92 const auto d = detail::shl(c, offset);
93 return Fxd::from_raw(detail::high(d));
97 const auto bias = detail::make_bias_for(Fxd::frac_bits, c);
98 const auto biased_c = detail::add(c, bias);
99 const auto d = detail::shl(biased_c, offset);
101 return Fxd::from_raw(detail::high(d));
114 template<fixed_po
int Fxd>
121 constexpr int w = detail::type_width<typename Fxd::raw_type>;
124 constexpr int offset = w - Fxd::frac_bits;
126 const auto raw_a = a.raw_value;
127 const auto raw_b = b.raw_value;
128 const auto c = detail::raw::mul<Fxd::bits>(raw_a, raw_b);
130 const auto d = detail::shl(c, offset);
132 return Fxd::from_raw(detail::high(d));
This is the namespace where the entire library is defined.