Skip to content

Commit

Permalink
adding a new constexpr test to lns
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Feb 24, 2024
1 parent c6b5c05 commit 53f7c72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
28 changes: 14 additions & 14 deletions include/universal/number/lns/lns_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class lns {
constexpr lns(unsigned int initial_value) noexcept { *this = initial_value; }
constexpr lns(unsigned long initial_value) noexcept { *this = initial_value; }
constexpr lns(unsigned long long initial_value) noexcept { *this = initial_value; }
constexpr lns(float initial_value) noexcept { *this = initial_value; }
constexpr lns(double initial_value) noexcept { *this = initial_value; }
constexpr lns(float initial_value) noexcept : _block{} { *this = initial_value; }
constexpr lns(double initial_value) noexcept : _block{} { *this = initial_value; }

// assignment operators
constexpr lns& operator=(signed char rhs) noexcept { return convert_signed(rhs); }
Expand Down Expand Up @@ -477,17 +477,17 @@ class lns {
return false;
}

explicit operator int() const noexcept { return to_signed<int>(); }
explicit operator long() const noexcept { return to_signed<long>(); }
explicit operator long long() const noexcept { return to_signed<long long>(); }
explicit operator float() const noexcept { return to_ieee754<float>(); }
explicit operator double() const noexcept { return to_ieee754<double>(); }
explicit constexpr operator int() const noexcept { return to_signed<int>(); }
explicit constexpr operator long() const noexcept { return to_signed<long>(); }
explicit constexpr operator long long() const noexcept { return to_signed<long long>(); }
explicit constexpr operator float() const noexcept { return to_ieee754<float>(); }
explicit constexpr operator double() const noexcept { return to_ieee754<double>(); }

// guard long double support to enable ARM and RISC-V embedded environments
#if LONG_DOUBLE_SUPPORT
lns(long double initial_value) noexcept { *this = initial_value; }
CONSTEXPRESSION lns& operator=(long double rhs) noexcept { return convert_ieee754(rhs); }
explicit operator long double() const noexcept { return to_ieee754<long double>(); }
explicit constexpr operator long double() const noexcept { return to_ieee754<long double>(); }
#endif

void debugConstexprParameters() {
Expand Down Expand Up @@ -592,8 +592,8 @@ class lns {
// NOTE: this is required to protect the rounding code below, which only works for values between [minpos, maxpos]
// TODO: this is all incredibly slow as we are creating special values and converting them to Real to compare
if constexpr (behavior == Behavior::Saturating) {
lns maxpos(SpecificValue::maxpos);
lns maxneg(SpecificValue::maxneg);
constexpr lns maxpos(SpecificValue::maxpos);
constexpr lns maxneg(SpecificValue::maxneg);
Real absoluteValue = std::abs(v);
//std::cout << "maxpos : " << to_binary(maxpos) << " : " << maxpos << '\n';
if (v > 0 && v >= Real(maxpos)) {
Expand All @@ -602,8 +602,8 @@ class lns {
if (v < 0 && v <= Real(maxneg)) {
return *this = maxneg;
}
lns minpos(SpecificValue::minpos);
lns<nbits + 1, rbits + 1, bt, xtra...> halfMinpos(SpecificValue::minpos); // in log space
constexpr lns minpos(SpecificValue::minpos);
constexpr lns<nbits + 1, rbits + 1, bt, xtra...> halfMinpos(SpecificValue::minpos); // in log space
//std::cout << "minpos : " << minpos << '\n';
//std::cout << "halfMinpos : " << halfMinpos << '\n';
if (absoluteValue <= Real(halfMinpos)) {
Expand All @@ -624,8 +624,8 @@ class lns {
return *this;
}


ExponentBlockBinary lnsExponent{ 0 };

extractFields(logv, s, unbiasedExponent, rawFraction, bits); // use native conversion
if (unbiasedExponent > 0) rawFraction |= (1ull << ieee754_parameter<Real>::fbits);
int radixPoint = ieee754_parameter<Real>::fbits - (static_cast<int>(unbiasedExponent) - ieee754_parameter<Real>::bias);
Expand Down Expand Up @@ -693,7 +693,7 @@ class lns {
if (s) lnsExponent.twosComplement();
}
}
// std::cout << "lns exponent : " << to_binary(lnsExponent) << " : " << lnsExponent << '\n';

_block = lnsExponent;
setsign(negative);

Expand Down
13 changes: 11 additions & 2 deletions static/lns/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ try {
// CONSTEXPRESSION Real b(1.0f); // constexpr of a native type conversion
// std::cout << to_binary(b) << " : " << b << '\n';

CONSTEXPRESSION Real c(SpecificValue::minpos); // constexpr of a special value in the encoding
std::cout << to_binary(c) << " : " << c << " == minpos" << '\n';
// TODO: conversion functions need to be constexpr
// CONSTEXPRESSION Real c(SpecificValue::minpos); // constexpr of a special value in the encoding
// constexpr float fminpos = float(c);
// float f = 1.0f;
// if (f < fminpos) {
// std::cout << f << " is smaller than lns minpos\n";
// }
// else {
// std::cout << f << " is larger than lns minpos\n";
// }
// std::cout << to_binary(c) << " : " << c << " == minpos" << '\n';

CONSTEXPRESSION Real d(SpecificValue::maxpos); // constexpr of a special value in the encoding
std::cout << to_binary(d) << " : " << d << " == maxpos" << '\n';
Expand Down

0 comments on commit 53f7c72

Please sign in to comment.