Skip to content

Commit

Permalink
We sadly have to normalize decimal32
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Feb 14, 2025
1 parent 1d6d9bf commit 55ebb50
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/boost/decimal/decimal32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,10 @@ constexpr auto operator+(decimal32 lhs, decimal32 rhs) noexcept -> decimal32
}
#endif

const auto lhs_components {lhs.to_components()};
const auto rhs_components {rhs.to_components()};
auto lhs_components {lhs.to_components()};
detail::normalize(lhs_components.sig, lhs_components.exp);
auto rhs_components {rhs.to_components()};
detail::normalize(rhs_components.sig, rhs_components.exp);

return detail::d32_add_impl<decimal32>(lhs_components, rhs_components);
}
Expand Down Expand Up @@ -971,8 +973,10 @@ constexpr auto operator-(decimal32 lhs, decimal32 rhs) noexcept -> decimal32
}
#endif

const auto lhs_components {lhs.to_components()};
auto lhs_components {lhs.to_components()};
detail::normalize(lhs_components.sig, lhs_components.exp);
auto rhs_components {rhs.to_components()};
detail::normalize(rhs_components.sig, rhs_components.exp);

// a - b = a + (-b)
rhs_components.sign = !rhs_components.sign;
Expand Down

0 comments on commit 55ebb50

Please sign in to comment.