scalar.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Typedef
25  Foam::scalar
26 
27 Description
28  Single floating point number identical to float or double depending on
29  whether WM_SP, WM_DP or WM_LP is defined.
30 
31 SourceFiles
32  scalar.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef scalar_H
37 #define scalar_H
38 
39 #include "floatScalar.H"
40 #include "doubleScalar.H"
41 #include "longDoubleScalar.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 #if defined(WM_SP)
46 
47 // Define scalar as a float
48 
49 namespace Foam
50 {
51  typedef floatScalar scalar;
52 
53  static const scalar great = floatScalarGreat;
54  static const scalar rootGreat = floatScalarRootGreat;
55  static const scalar vGreat = floatScalarVGreat;
56  static const scalar rootVGreat = floatScalarRootVGreat;
57  static const scalar small = floatScalarSmall;
58  static const scalar rootSmall = floatScalarRootSmall;
59  static const scalar vSmall = floatScalarVSmall;
60  static const scalar rootVSmall = floatScalarRootVSmall;
61  static const scalar NaN = floatScalarNaN;
62 }
63 
64 #elif defined(WM_DP)
65 
66 // Define scalar as a double
67 
68 namespace Foam
69 {
70  typedef doubleScalar scalar;
71 
72  static const scalar great = doubleScalarGreat;
73  static const scalar rootGreat = doubleScalarRootGreat;
74  static const scalar vGreat = doubleScalarVGreat;
75  static const scalar rootVGreat = doubleScalarRootVGreat;
76  static const scalar small = doubleScalarSmall;
77  static const scalar rootSmall = doubleScalarRootSmall;
78  static const scalar vSmall = doubleScalarVSmall;
79  static const scalar rootVSmall = doubleScalarRootVSmall;
80  static const scalar NaN = doubleScalarNaN;
81 }
82 
83 #elif defined(WM_LP)
84 
85 // Define scalar as a long double
86 
87 namespace Foam
88 {
89  typedef longDoubleScalar scalar;
90 
91  static const scalar great = longDoubleScalarGreat;
92  static const scalar rootGreat = longDoubleScalarRootGreat;
93  static const scalar vGreat = longDoubleScalarVGreat;
94  static const scalar rootVGreat = longDoubleScalarRootVGreat;
95  static const scalar small = longDoubleScalarSmall;
96  static const scalar rootSmall = longDoubleScalarRootSmall;
97  static const scalar vSmall = longDoubleScalarVSmall;
98  static const scalar rootVSmall = longDoubleScalarRootVSmall;
99  static const scalar NaN = longDoubleScalarNaN;
100 }
101 
102 #else
103 
104  #error "Precision not set, please set either WM_SP, WM_DP or WM_LP"
105 
106 #endif
107 
108 //- Deprecated limit constant for backward-compatibility
109 namespace Foam
110 {
111  static const scalar GREAT = great;
112  static const scalar ROOTGREAT = rootGreat;
113  static const scalar VGREAT = vGreat;
114  static const scalar ROOTVGREAT = rootVGreat;
115  static const scalar SMALL = small;
116  static const scalar ROOTSMALL = rootSmall;
117  static const scalar VSMALL = vSmall;
118  static const scalar ROOTVSMALL = rootVSmall;
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 // Additional global and transcendental functions
124 
125 namespace Foam
126 {
127  //- Read a single scalar from an input stream
128  scalar readScalar(Istream& is);
129 
130  //- Normalised upper incomplete gamma function
131  scalar incGammaRatio_Q(const scalar a, const scalar x);
132 
133  //- Normalised lower incomplete gamma function
134  scalar incGammaRatio_P(const scalar a, const scalar x);
135 
136  //- Upper incomplete gamma function
137  scalar incGamma_Q(const scalar a, const scalar x);
138 
139  //- Lower incomplete gamma function
140  scalar incGamma_P(const scalar a, const scalar x);
141 
142  //- Inverse normalised lower incomplete gamma function
143  scalar invIncGammaRatio_P(const scalar a, const scalar P);
144 
145  //- Compute the power of the number x to the integer e
146  inline scalar integerPow(const scalar x, const label e);
147 
148  //- Compute the power of the number x to the reciprocal integer 1/e
149  inline scalar integerRoot(const scalar x, const label e);
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #include "scalarI.H"
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #endif
160 
161 // ************************************************************************* //
static Type NaN()
Return a primitive with all components set to NaN.
Namespace for OpenFOAM.
static const doubleScalar doubleScalarRootVGreat
Definition: doubleScalar.H:65
scalar integerRoot(const scalar x, const label e)
Compute the power of the number x to the reciprocal integer 1/e.
Definition: scalarI.H:55
static const longDoubleScalar longDoubleScalarNaN
static const floatScalar floatScalarRootVSmall
Definition: floatScalar.H:66
const doubleScalar e
Definition: doubleScalar.H:105
static const longDoubleScalar longDoubleScalarSmall
static const scalar ROOTSMALL
Definition: scalar.H:116
static const scalar SMALL
Definition: scalar.H:115
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
static const longDoubleScalar longDoubleScalarRootGreat
static const scalar VGREAT
Definition: scalar.H:113
scalar incGamma_P(const scalar a, const scalar x)
Lower incomplete gamma function.
Definition: incGamma.C:447
static const longDoubleScalar longDoubleScalarGreat
static const scalar ROOTVGREAT
Definition: scalar.H:114
static const floatScalar floatScalarGreat
Definition: floatScalar.H:63
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
static const doubleScalar doubleScalarSmall
Definition: doubleScalar.H:61
static const doubleScalar doubleScalarNaN
Definition: doubleScalar.H:72
static const floatScalar floatScalarRootVGreat
Definition: floatScalar.H:65
static const scalar ROOTVSMALL
Definition: scalar.H:118
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
static const longDoubleScalar longDoubleScalarRootVSmall
static const floatScalar floatScalarRootGreat
Definition: floatScalar.H:68
static const longDoubleScalar longDoubleScalarVSmall
static const longDoubleScalar longDoubleScalarRootVGreat
scalar invIncGammaRatio_P(const scalar a, const scalar P)
Inverse normalised lower incomplete gamma function.
Definition: invIncGamma.C:115
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
static const longDoubleScalar longDoubleScalarVGreat
static const doubleScalar doubleScalarRootGreat
Definition: doubleScalar.H:68
static const floatScalar floatScalarRootSmall
Definition: floatScalar.H:69
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
static const doubleScalar doubleScalarGreat
Definition: doubleScalar.H:63
static const scalar VSMALL
Definition: scalar.H:117
static const scalar ROOTGREAT
Definition: scalar.H:112
static const floatScalar floatScalarVSmall
Definition: floatScalar.H:58
scalar incGamma_Q(const scalar a, const scalar x)
Upper incomplete gamma function.
Definition: incGamma.C:441
static const scalar GREAT
Definition: scalar.H:111
scalar incGammaRatio_P(const scalar a, const scalar x)
Normalised lower incomplete gamma function.
Definition: incGamma.C:435
static const floatScalar floatScalarNaN
Definition: floatScalar.H:72
static const doubleScalar doubleScalarVSmall
Definition: doubleScalar.H:58
long double longDoubleScalar
Lang double precision floating point scalar type.
static const floatScalar floatScalarSmall
Definition: floatScalar.H:61
scalar incGammaRatio_Q(const scalar a, const scalar x)
Normalised upper incomplete gamma function.
Definition: incGamma.C:221
static const doubleScalar doubleScalarVGreat
Definition: doubleScalar.H:56
static const doubleScalar doubleScalarRootSmall
Definition: doubleScalar.H:69
static const doubleScalar doubleScalarRootVSmall
Definition: doubleScalar.H:66
static const longDoubleScalar longDoubleScalarRootSmall
static const floatScalar floatScalarVGreat
Definition: floatScalar.H:56