1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
15 // Thankfully, IEEE Std 1003.1, 2004 Edition says that signbit is a macro,
16 // hence it's safe to use ifdef.
21 inline int signbitfunc(double d)
23 return *((unsigned char*)&d) & 0x80;
27 // Probably Intel, assume little endian
28 inline int signbitfunc(double d)
30 return ((unsigned char*)&d)[sizeof(double)-1] & 0x80;
35 #define signbit(d) signbitfunc(d)
39 /** A class which behaves almost, but not quite, entirely unlike
40 * a floating-point value.
42 * It is used as a member of a union (in Value.hh);
43 * it MUST NOT have a constructor.
46 /// Implicit conversion
47 operator double() const { return value; }
49 /// Assignment from a proper double
50 const ttcn3float& operator=(double d) {
55 /// Address-of, for scanf
56 double* operator&() { return &value; }
58 const ttcn3float& operator+=(double d) {
63 const ttcn3float& operator-=(double d) {
68 const ttcn3float& operator*=(double d) {
73 const ttcn3float& operator/=(double d) {
78 bool operator<(double d) const {
80 return false; // TTCN-3 special: NaN is bigger than anything except NaN
83 return true; // TTCN-3 special: NaN is bigger than anything except NaN
85 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
86 return signbit(value) && !signbit(d); // value negative, d positive
88 else { // finally, the sensible behavior
93 bool operator>(double d) const {
95 return true; // TTCN-3 special: NaN is bigger than anything except NaN
98 return false; // TTCN-3 special: NaN is bigger than anything except NaN
100 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
101 return !signbit(value) && signbit(d); // value positive, d negative
103 else { // finally, the sensible behavior
108 bool operator==(double d) const {
110 return !!isnan(d); // TTCN-3 special: NaN is bigger than anything except NaN
115 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
116 return signbit(value) == signbit(d);
118 else { // finally, the sensible behavior
126 /** Replacement for a user-defined constructor that ttcn3float can't have */
127 inline ttcn3float make_ttcn3float(double f) {
128 ttcn3float retval = { f };
132 #endif /* TTCN3FLOAT_HH_ */