Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 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 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Bibo, Zoltan | |
11 | * Delic, Adam | |
12 | * Forstner, Matyas | |
13 | * Raduly, Csaba | |
14 | * Szabo, Janos Zoltan – initial implementation | |
15 | * | |
16 | ******************************************************************************/ | |
970ed795 EL |
17 | #ifndef _Common_Real_HH |
18 | #define _Common_Real_HH | |
19 | ||
20 | #include "string.hh" | |
21 | #include <math.h> | |
22 | ||
23 | // older versions of gcc do not have numeric_limits<double> or it is wrong | |
24 | // and they do not have constants defined by C99 standard | |
25 | #ifdef INFINITY | |
26 | static const double REAL_INFINITY = INFINITY; | |
27 | #else | |
28 | #include <float.h> | |
29 | static const double REAL_INFINITY = (DBL_MAX*DBL_MAX); | |
30 | #endif | |
31 | ||
32 | #ifdef NAN | |
33 | static const double REAL_NAN = NAN; | |
34 | #else | |
35 | static const double REAL_NAN = (REAL_INFINITY-REAL_INFINITY); | |
36 | #endif | |
37 | ||
38 | namespace Common { | |
39 | ||
40 | class Location; | |
41 | ||
42 | /** | |
43 | * \defgroup Real Real type and related functions | |
44 | * | |
45 | * Real type is used to represent those real/float values which will | |
46 | * be used in TITAN run-time environment, in the compiler. | |
47 | * | |
48 | * @{ | |
49 | */ | |
50 | ||
51 | /** Real typedef */ | |
52 | ||
53 | typedef double Real; | |
54 | ||
55 | /** +/- infinity and not_a_number are non-numeric float values in ttcn-3, | |
56 | these special values cannot be used in some places */ | |
57 | bool isSpecialFloatValue(const Real& r); | |
58 | ||
59 | /** | |
60 | * Converts the Common::Real value to string. | |
61 | * | |
62 | * The returned string looks like this: | |
63 | * | |
64 | * <pre> | |
65 | ( | |
66 | ( | |
67 | ([\-][1-9]\.(([0-9]+[1-9])|0)) | |
68 | | | |
69 | ([\-]0\.([0-9]+[1-9])) | |
70 | ) | |
71 | "e" | |
72 | (([\-][1-9][0-9]*)|0) | |
73 | ) | |
74 | | | |
75 | (0\.0e0) | |
76 | | | |
77 | "INF" | |
78 | | | |
79 | "-INF" | |
80 | * </pre> | |
81 | */ | |
82 | string Real2string(const Real& r); | |
83 | ||
84 | /** Returns the C++ equivalent of value r */ | |
85 | string Real2code(const Real& r); | |
86 | ||
87 | /** | |
88 | * Converts the string value to Common::Real. | |
89 | */ | |
90 | Real string2Real(const char *s, const Location& loc); | |
91 | inline Real string2Real(const string& s, const Location& loc) | |
92 | { return string2Real(s.c_str(), loc); } | |
93 | /** @} end of Real group */ | |
94 | ||
95 | } // namespace Common | |
96 | ||
97 | #endif // _Common_Real_HH |