1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 ///////////////////////////////////////////////////////////////////////////////
13 /* TTCN-3 float values that have absolute value smaller than this
14 are displayed in exponential notation. */
15 #define MIN_DECIMAL_FLOAT 1.0E-4
16 /* TTCN-3 float values that have absolute value larger or equal than this
17 are displayed in exponential notation. */
18 #define MAX_DECIMAL_FLOAT 1.0E+10
22 // Thankfully, IEEE Std 1003.1, 2004 Edition says that signbit is a macro,
23 // hence it's safe to use ifdef.
28 inline int signbitfunc(double d)
30 return *((unsigned char*)&d) & 0x80;
34 // Probably Intel, assume little endian
35 inline int signbitfunc(double d)
37 return ((unsigned char*)&d)[sizeof(double)-1] & 0x80;
42 #define signbit(d) signbitfunc(d)
46 /** A class which behaves almost, but not quite, entirely unlike
47 * a floating-point value.
49 * It is used as a member of a union (in Value.hh);
50 * it MUST NOT have a constructor.
53 /// Implicit conversion
54 operator double() const { return value; }
56 /// Assignment from a proper double
57 const ttcn3float& operator=(double d) {
62 /// Address-of, for scanf
63 double* operator&() { return &value; }
65 const ttcn3float& operator+=(double d) {
70 const ttcn3float& operator-=(double d) {
75 const ttcn3float& operator*=(double d) {
80 const ttcn3float& operator/=(double d) {
85 bool operator<(double d) const {
87 return false; // TTCN-3 special: NaN is bigger than anything except NaN
90 return true; // TTCN-3 special: NaN is bigger than anything except NaN
92 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
93 return signbit(value) && !signbit(d); // value negative, d positive
95 else { // finally, the sensible behavior
100 bool operator>(double d) const {
102 return true; // TTCN-3 special: NaN is bigger than anything except NaN
105 return false; // TTCN-3 special: NaN is bigger than anything except NaN
107 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
108 return !signbit(value) && signbit(d); // value positive, d negative
110 else { // finally, the sensible behavior
115 bool operator==(double d) const {
117 return !!isnan(d); // TTCN-3 special: NaN is bigger than anything except NaN
122 else if (value==0.0 && d==0.0) { // does not distinguish -0.0
123 return signbit(value) == signbit(d);
125 else { // finally, the sensible behavior
133 /** Replacement for a user-defined constructor that ttcn3float can't have */
134 inline ttcn3float make_ttcn3float(double f) {
135 ttcn3float retval = { f };
139 #endif /* TTCN3FLOAT_HH_ */