Skip to content

Commit

Permalink
Bug fix: fma special case handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 15, 2018
1 parent bcff423 commit 5bbcee1
Show file tree
Hide file tree
Showing 22 changed files with 326 additions and 300 deletions.
2 changes: 1 addition & 1 deletion education/posit/basic_operators.cpp
Expand Up @@ -10,7 +10,7 @@
// quick helper to report on a posit's specialness
template<size_t nbits, size_t es>
void checkSpecialCases(sw::unum::posit<nbits, es> p) {
std::cout << "posit is " << (p.isZero() ? "zero " : "non-zero ") << (p.isPositive() ? "positive " : "negative ") << (p.isNaR() ? "Not a Real" : "Its a Real") << std::endl;
std::cout << "posit is " << (p.iszero() ? "zero " : "non-zero ") << (p.ispos() ? "positive " : "negative ") << (p.isnar() ? "Not a Real" : "Its a Real") << std::endl;
}

// Demonstrate basic arithmetic with posit numbers
Expand Down
6 changes: 3 additions & 3 deletions education/posit/enumeration.cpp
Expand Up @@ -25,7 +25,7 @@ try {
}
// reverse enumeration from NaR to 0
cout << "Decrement-based descention from NaR to 0 and back to NaR\n";
p.setToNaR();
p.setnar();
for (long i = (size_t(1) << nbits); i >= 0; --i) {
cout << components(p--) << '\n';
}
Expand All @@ -40,7 +40,7 @@ try {
}
// reverse enumeration from NaR to 0
cout << "Decrement-based descention from NaR to 0 and back to NaR\n";
p.setToNaR();
p.setnar();
for (long i = (size_t(1) << nbits); i >= 0; --i) {
cout << pretty_print(p--) << '\n';
}
Expand All @@ -55,7 +55,7 @@ try {
}
// reverse enumeration from NaR to 0
cout << "Decrement-based descention from NaR to 0 and back to NaR\n";
p.setToNaR();
p.setnar();
for (long i = (size_t(1) << nbits); i >= 0; --i) {
cout << info_print(p--, nbits) << '\n';
}
Expand Down
10 changes: 5 additions & 5 deletions education/posit/exceptions.cpp
Expand Up @@ -32,7 +32,7 @@ try {

try {
pa = 1.0f;
pb.setToNaR();
pb.setnar();
pc = pa / pb;
cout << "Incorrect: division by nar exception didn't fire" << endl;
}
Expand All @@ -41,7 +41,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa / pb;
cout << "Incorrect: numerator is nar exception didn't fire" << endl;
Expand All @@ -51,7 +51,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa + pb;
cout << "Incorrect: operand is nar exception didn't fire" << endl;
Expand All @@ -61,7 +61,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa - pb;
cout << "Incorrect: operand is nar exception didn't fire" << endl;
Expand All @@ -71,7 +71,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa * pb; // TODO: operator *= throws the same exception, but for some reason we can't catch it here
cout << "Incorrect: operand is nar exception didn't fire" << endl;
Expand Down
10 changes: 5 additions & 5 deletions education/posit/signalling_nar.cpp
Expand Up @@ -32,7 +32,7 @@ try {

try {
pa = 1.0f;
pb.setToNaR();
pb.setnar();
pc = pa / pb;
cout << "Correct: division by nar exception didn't fire as it is not enabled" << endl;
}
Expand All @@ -41,7 +41,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa / pb;
cout << "Correct: numerator is nar exception didn't fire as it is not enabled" << endl;
Expand All @@ -51,7 +51,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa + pb;
cout << "Correct: operand is nar exception didn't fire as it is not enabled" << endl;
Expand All @@ -61,7 +61,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa - pb;
cout << "Correct: operand is nar exception didn't fire as it is not enabled" << endl;
Expand All @@ -71,7 +71,7 @@ try {
}

try {
pa.setToNaR();
pa.setnar();
pb = 1.0f;
pc = pa * pb;
cout << "Correct: operand is nar exception didn't fire as it is not enabled" << endl;
Expand Down
4 changes: 2 additions & 2 deletions examples/playground/serialization.cpp
Expand Up @@ -48,9 +48,9 @@ try {
bitblock<3> three; three.set(2, true); str = to_hex(three); cout << "three: " << str << endl;
bitblock<4> four; four.set(3, true); str = to_hex(four); cout << "four : " << str << endl;

p.setToZero();
p.setzero();
cout << "posit value 0: " << p << endl;
p.setToNaR();
p.setnar();
cout << "posit value NaR: " << p << endl;

return EXIT_SUCCESS;
Expand Down
7 changes: 4 additions & 3 deletions float/quire.hpp
Expand Up @@ -174,7 +174,7 @@ class quire {

template<size_t fbits>
quire& operator+=(const sw::unum::value<fbits>& rhs) {
if (rhs.isZero()) return *this;
if (rhs.iszero()) return *this;
int i, f, scale = rhs.scale();
if (scale > int(half_range)) {
throw operand_too_large_for_quire{};
Expand Down Expand Up @@ -414,8 +414,9 @@ class quire {
int max_scale() const { return half_range; }
int min_scale() const { return -int(half_range); }
int capacity_range() const { return capacity; }
bool isNegative() const { return _sign; }
bool isZero() const { return _capacity.none() && _upper.none() && _lower.none(); }
bool isneg() const { return _sign; }
bool ispos() const { return !_sign; }
bool iszero() const { return _capacity.none() && _upper.none() && _lower.none(); }

// Return value of the sign bit: true indicates a negative number, false a positive number or zero
bool get_sign() const { return _sign; }
Expand Down
4 changes: 2 additions & 2 deletions posit/math_sqrt.hpp
Expand Up @@ -182,8 +182,8 @@ namespace sw {
template<size_t nbits, size_t es>
inline posit<nbits, es> sqrt(const posit<nbits, es>& a) {
posit<nbits, es> p;
if (a.isNegative() || a.isNaR()) {
p.setToNaR();
if (a.isneg() || a.isnar()) {
p.setnar();
return p;
}

Expand Down

0 comments on commit 5bbcee1

Please sign in to comment.