Titan Core Initial Contribution
[deliverable/titan.core.git] / compiler2 / Real.hh
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 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef _Common_Real_HH
9 #define _Common_Real_HH
10
11 #include "string.hh"
12 #include <math.h>
13
14 // older versions of gcc do not have numeric_limits<double> or it is wrong
15 // and they do not have constants defined by C99 standard
16 #ifdef INFINITY
17 static const double REAL_INFINITY = INFINITY;
18 #else
19 #include <float.h>
20 static const double REAL_INFINITY = (DBL_MAX*DBL_MAX);
21 #endif
22
23 #ifdef NAN
24 static const double REAL_NAN = NAN;
25 #else
26 static const double REAL_NAN = (REAL_INFINITY-REAL_INFINITY);
27 #endif
28
29 namespace Common {
30
31 class Location;
32
33 /**
34 * \defgroup Real Real type and related functions
35 *
36 * Real type is used to represent those real/float values which will
37 * be used in TITAN run-time environment, in the compiler.
38 *
39 * @{
40 */
41
42 /** Real typedef */
43
44 typedef double Real;
45
46 /** +/- infinity and not_a_number are non-numeric float values in ttcn-3,
47 these special values cannot be used in some places */
48 bool isSpecialFloatValue(const Real& r);
49
50 /**
51 * Converts the Common::Real value to string.
52 *
53 * The returned string looks like this:
54 *
55 * <pre>
56 (
57 (
58 ([\-][1-9]\.(([0-9]+[1-9])|0))
59 |
60 ([\-]0\.([0-9]+[1-9]))
61 )
62 "e"
63 (([\-][1-9][0-9]*)|0)
64 )
65 |
66 (0\.0e0)
67 |
68 "INF"
69 |
70 "-INF"
71 * </pre>
72 */
73 string Real2string(const Real& r);
74
75 /** Returns the C++ equivalent of value r */
76 string Real2code(const Real& r);
77
78 /**
79 * Converts the string value to Common::Real.
80 */
81 Real string2Real(const char *s, const Location& loc);
82 inline Real string2Real(const string& s, const Location& loc)
83 { return string2Real(s.c_str(), loc); }
84 /** @} end of Real group */
85
86 } // namespace Common
87
88 #endif // _Common_Real_HH
This page took 0.03585 seconds and 5 git commands to generate.