From 09ae42f5add46dbf15808c6d410ce19597d35ac6 Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sat, 2 Mar 2024 21:30:11 +0100 Subject: big_int_t: Fix & test free math function wrapper (min, max, clamp ..) --- include/jau/mp/big_int_t.hpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'include/jau') diff --git a/include/jau/mp/big_int_t.hpp b/include/jau/mp/big_int_t.hpp index 81aa8a4..9d91311 100644 --- a/include/jau/mp/big_int_t.hpp +++ b/include/jau/mp/big_int_t.hpp @@ -1557,27 +1557,26 @@ namespace jau { inline mp::big_int_t abs(mp::big_int_t x) noexcept { return x.abs(); } inline mp::big_int_t pow(mp::big_int_t b, mp::big_int_t e) { return b.pow(e); } - constexpr const mp::big_int_t& min(const mp::big_int_t& x, const mp::big_int_t& y) noexcept { + inline const mp::big_int_t& min(const mp::big_int_t& x, const mp::big_int_t& y) noexcept { return x < y ? x : y; } - constexpr const mp::big_int_t& max(const mp::big_int_t& x, const mp::big_int_t& y) noexcept { + inline const mp::big_int_t& max(const mp::big_int_t& x, const mp::big_int_t& y) noexcept { return x > y ? x : y; } - constexpr const mp::big_int_t& clamp(const mp::big_int_t& x, const mp::big_int_t& min_val, const mp::big_int_t& max_val) noexcept { + inline const mp::big_int_t& clamp(const mp::big_int_t& x, const mp::big_int_t& min_val, const mp::big_int_t& max_val) noexcept { return min(max(x, min_val), max_val); } - constexpr mp::big_int_t& min(mp::big_int_t& x, mp::big_int_t& y) noexcept { + inline mp::big_int_t& min(mp::big_int_t& x, mp::big_int_t& y) noexcept { return x < y ? x : y; } - constexpr mp::big_int_t max(mp::big_int_t& x, mp::big_int_t& y) noexcept { + inline mp::big_int_t& max(mp::big_int_t& x, mp::big_int_t& y) noexcept { return x > y ? x : y; } - constexpr mp::big_int_t& clamp(mp::big_int_t& x, mp::big_int_t& min_val, mp::big_int_t& max_val) noexcept { + inline mp::big_int_t& clamp(mp::big_int_t& x, mp::big_int_t& min_val, mp::big_int_t& max_val) noexcept { return min(max(x, min_val), max_val); } - inline mp::big_int_t gcd(const mp::big_int_t& a, const mp::big_int_t& b) noexcept { mp::big_int_t a_ = abs(a); mp::big_int_t b_ = abs(b); @@ -1589,9 +1588,11 @@ namespace jau { return a_; } - std::ostream& operator<<(std::ostream& out, const mp::big_int_t& v) { + /**@}*/ +} + +namespace std { + inline std::ostream& operator<<(std::ostream& out, const jau::mp::big_int_t& v) { return out << v.to_dec_string(); } - - /**@}*/ } -- cgit v1.2.3