Skip to content
Permalink
Browse files

Bug fix: fma special case handling

  • Loading branch information...
Ravenwater committed Aug 15, 2018
1 parent bcff423 commit 5bbcee19ec46276685f8314aaad669081ab94b30
@@ -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
@@ -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';
}
@@ -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';
}
@@ -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';
}
@@ -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;
}
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
}
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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{};
@@ -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; }
@@ -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;
}

Oops, something went wrong.

0 comments on commit 5bbcee1

Please sign in to comment.
You can’t perform that action at this time.