Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FixedPointTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::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<int>::max());
}
}

Expand Down
8 changes: 4 additions & 4 deletions include/FixedPoint/FixedPointHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef FIXEDPOINTHELPERS_HPP
#define FIXEDPOINTHELPERS_HPP
#include <cmath>
#include <limits.h>
#include <limits>
#include <algorithm>
#include <stdint.h>

Expand Down Expand Up @@ -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<double>::max() ? std::numeric_limits<int>::max() :
v == 0 ? std::numeric_limits<int>::min() :
v < 1 ? ilogb(v*2)-1 :
v >= 2 ? ilogb(v/2) + 1 :
0;
Expand Down
2 changes: 1 addition & 1 deletion include/FixedPoint/MultiwordIntegerSpecialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MultiwordInteger<1, _storageType> {
constexpr MultiwordInteger<size, storageType>& operator--() { s[0]--; return *this; }
constexpr MultiwordInteger<size, storageType> operator--(int) { MultiwordInteger<size, storageType> r(*this); --*this; return r; }

constexpr MultiwordInteger<size, storageType> operator-() const { return MultiwordInteger<size, storageType>(storageType(-s[0])); }
constexpr MultiwordInteger<size, storageType> operator-() const { return MultiwordInteger<size, storageType>(storageType(-signedType(s[0]))); }

constexpr MultiwordInteger<size, storageType>& operator &=(MultiwordInteger<size, storageType> const &o) { s[0] &= o.s[0]; return *this; }
constexpr MultiwordInteger<size, storageType>& operator |=(MultiwordInteger<size, storageType> const &o) { s[0] |= o.s[0]; return *this; }
Expand Down