Skip to content
Snippets Groups Projects
Commit b0943d33 authored by Botond Baranyi's avatar Botond Baranyi Committed by Gerrit Code Review
Browse files

Merge "build experiment: lets use the C++11 signbit function instead of...

Merge "build experiment: lets use the C++11 signbit function instead of platform dependent buggy macros (needs to be tested on all platforms)"
parents 76d26dd5 c1d96b4d
No related branches found
No related tags found
No related merge requests found
...@@ -14,9 +14,7 @@ ...@@ -14,9 +14,7 @@
#ifndef TTCN3FLOAT_HH_ #ifndef TTCN3FLOAT_HH_
#define TTCN3FLOAT_HH_ #define TTCN3FLOAT_HH_
// TODO: once we can use C++11 as the base platform replace with cmath #include <cmath>
// this way the signedbit will become a defined function instead of a macro
#include <math.h>
/* TTCN-3 float values that have absolute value smaller than this /* TTCN-3 float values that have absolute value smaller than this
are displayed in exponential notation. */ are displayed in exponential notation. */
...@@ -25,31 +23,31 @@ ...@@ -25,31 +23,31 @@
are displayed in exponential notation. */ are displayed in exponential notation. */
#define MAX_DECIMAL_FLOAT 1.0E+10 #define MAX_DECIMAL_FLOAT 1.0E+10
#ifndef signbit //#ifndef signbit
// Probably Solaris. // Probably Solaris.
// Thankfully, IEEE Std 1003.1, 2004 Edition says that signbit is a macro, // Thankfully, IEEE Std 1003.1, 2004 Edition says that signbit is a macro,
// hence it's safe to use ifdef. // hence it's safe to use ifdef.
#ifdef __sparc //#ifdef __sparc
// Big endian //// Big endian
inline int signbitfunc(double d) //inline int signbitfunc(double d)
{ //{
return *((unsigned char*)&d) & 0x80; // return *((unsigned char*)&d) & 0x80;
} //}
#else //#else
// Probably Intel, assume little endian // Probably Intel, assume little endian
inline int signbitfunc(double d) //inline int signbitfunc(double d)
{ //{
return ((unsigned char*)&d)[sizeof(double)-1] & 0x80; // return ((unsigned char*)&d)[sizeof(double)-1] & 0x80;
} //}
#endif //#endif
#define signbit(d) signbitfunc(d) //#define signbit(d) signbitfunc(d)
#endif // def signbit //#endif // def signbit
/** A class which behaves almost, but not quite, entirely unlike /** A class which behaves almost, but not quite, entirely unlike
* a floating-point value. * a floating-point value.
...@@ -91,14 +89,14 @@ struct ttcn3float { ...@@ -91,14 +89,14 @@ struct ttcn3float {
} }
bool operator<(double d) const { bool operator<(double d) const {
if (isnan(value)) { if (std::isnan(value)) {
return false; // TTCN-3 special: NaN is bigger than anything except NaN return false; // TTCN-3 special: NaN is bigger than anything except NaN
} }
else if (isnan(d)) { else if (std::isnan(d)) {
return true; // TTCN-3 special: NaN is bigger than anything except NaN return true; // TTCN-3 special: NaN is bigger than anything except NaN
} }
else if (value==0.0 && d==0.0) { // does not distinguish -0.0 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
return signbit(value) && !signbit(d); // value negative, d positive return std::signbit(value) && !std::signbit(d); // value negative, d positive
} }
else { // finally, the sensible behavior else { // finally, the sensible behavior
return value < d; return value < d;
...@@ -106,14 +104,14 @@ struct ttcn3float { ...@@ -106,14 +104,14 @@ struct ttcn3float {
} }
bool operator>(double d) const { bool operator>(double d) const {
if (isnan(value)) { if (std::isnan(value)) {
return true; // TTCN-3 special: NaN is bigger than anything except NaN return true; // TTCN-3 special: NaN is bigger than anything except NaN
} }
else if (isnan(d)) { else if (std::isnan(d)) {
return false; // TTCN-3 special: NaN is bigger than anything except NaN return false; // TTCN-3 special: NaN is bigger than anything except NaN
} }
else if (value==0.0 && d==0.0) { // does not distinguish -0.0 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
return !signbit(value) && signbit(d); // value positive, d negative return !std::signbit(value) && std::signbit(d); // value positive, d negative
} }
else { // finally, the sensible behavior else { // finally, the sensible behavior
return value > d; return value > d;
...@@ -121,14 +119,14 @@ struct ttcn3float { ...@@ -121,14 +119,14 @@ struct ttcn3float {
} }
bool operator==(double d) const { bool operator==(double d) const {
if (isnan(value)) { if (std::isnan(value)) {
return !!isnan(d); // TTCN-3 special: NaN is bigger than anything except NaN return !!std::isnan(d); // TTCN-3 special: NaN is bigger than anything except NaN
} }
else if (isnan(d)) { else if (std::isnan(d)) {
return false; return false;
} }
else if (value==0.0 && d==0.0) { // does not distinguish -0.0 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
return signbit(value) == signbit(d); return std::signbit(value) == std::signbit(d);
} }
else { // finally, the sensible behavior else { // finally, the sensible behavior
return value == d; return value == d;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment