diff --git a/FixedPointTests.cpp b/FixedPointTests.cpp index c3e01da..ea150d7 100644 --- a/FixedPointTests.cpp +++ b/FixedPointTests.cpp @@ -612,12 +612,12 @@ SUITE(MultiwordInteger) { CHECK_EQUAL(FixedPointHelpers::nlz(uint32_t(1)), 31); CHECK_EQUAL(FixedPointHelpers::nlz(uint16_t(1)), 15); CHECK_EQUAL(FixedPointHelpers::nlz(uint8_t(1)), 7); - CHECK_EQUAL(FixedPointHelpers::ilogb(0), INT_MIN); + CHECK_EQUAL(FixedPointHelpers::ilogb(0), std::numeric_limits::min()); CHECK_EQUAL(FixedPointHelpers::ilogb(0.5), -1); CHECK_EQUAL(FixedPointHelpers::ilogb(2), 1); CHECK_EQUAL(FixedPointHelpers::ilogb(-2), 1); CHECK_EQUAL(FixedPointHelpers::ilogb(NAN), 0); - CHECK_EQUAL(FixedPointHelpers::ilogb(INFINITY), INT_MAX); + CHECK_EQUAL(FixedPointHelpers::ilogb(INFINITY), std::numeric_limits::max()); } } diff --git a/include/FixedPoint/FixedPointHelpers.hpp b/include/FixedPoint/FixedPointHelpers.hpp index 1e35c0d..9c019c8 100644 --- a/include/FixedPoint/FixedPointHelpers.hpp +++ b/include/FixedPoint/FixedPointHelpers.hpp @@ -4,7 +4,7 @@ #ifndef FIXEDPOINTHELPERS_HPP #define FIXEDPOINTHELPERS_HPP #include -#include +#include #include #include @@ -60,9 +60,9 @@ namespace FixedPointHelpers { constexpr int ilogb(double v) { return v < 0 ? ilogb(-v) : - std::isnan(v) ? 0 : - std::isinf(v) ? INT_MAX : - v == 0 ? INT_MIN : + !(v == v) ? 0 : // NAN check + v > std::numeric_limits::max() ? std::numeric_limits::max() : + v == 0 ? std::numeric_limits::min() : v < 1 ? ilogb(v*2)-1 : v >= 2 ? ilogb(v/2) + 1 : 0; diff --git a/include/FixedPoint/MultiwordIntegerSpecialization.hpp b/include/FixedPoint/MultiwordIntegerSpecialization.hpp index 7551c4f..79143fe 100644 --- a/include/FixedPoint/MultiwordIntegerSpecialization.hpp +++ b/include/FixedPoint/MultiwordIntegerSpecialization.hpp @@ -63,7 +63,7 @@ class MultiwordInteger<1, _storageType> { constexpr MultiwordInteger& operator--() { s[0]--; return *this; } constexpr MultiwordInteger operator--(int) { MultiwordInteger r(*this); --*this; return r; } - constexpr MultiwordInteger operator-() const { return MultiwordInteger(storageType(-s[0])); } + constexpr MultiwordInteger operator-() const { return MultiwordInteger(storageType(-signedType(s[0]))); } constexpr MultiwordInteger& operator &=(MultiwordInteger const &o) { s[0] &= o.s[0]; return *this; } constexpr MultiwordInteger& operator |=(MultiwordInteger const &o) { s[0] |= o.s[0]; return *this; }