initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / postProcessing / dataConversion / foamToFieldview9 / floatScalar.H
blob5ae46380f61a37aacb66da7f5c96f2490d73a0a1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Typedef
26     Foam::floatScalar
28 Description
29     single floating point number identical to float
31 SourceFiles
32     floatScalar.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef floatScalar_H
37 #define floatScalar_H
39 #include "label.H"
40 #include "word.H"
42 #include <cmath>
44 #ifdef ibm
45     float lgamma(float);
46 #endif
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Define floatScalar as a float
51 namespace Foam
53     typedef float floatScalar;
57 // Define floatScalar as a float
59 namespace Foam
61     typedef float floatScalar;
63     // Largest and smallest floatScalar values allowed in certain parts of the code
64     // (6 is the number of significant figures in an
65     //  IEEE single precision number.  See limits.h or float.h)
66     static const floatScalar GREAT = 1.0e+6;
67     static const floatScalar VGREAT = 1.0e+37;
68     static const floatScalar SMALL = 1.0e-6;
69     static const floatScalar VSMALL = 1.0e-37;
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 #include "pTraits.H"
76 #include "products.H"
77 #include "direction.H"
79 namespace Foam
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 // template specialisation for pTraits<floatScalar>
85 template<>
86 class pTraits<floatScalar>
88     floatScalar p_;
90 public:
92     //- Component type
93     typedef floatScalar cmptType;
95     // Member constants
97         enum
98         {
99             dim = 3,         // Dimensionality of space
100             rank = 0,        // Rank od floatScalar is 0
101             nComponents = 1  // Number of components in floatScalar is 1
102         };
104     // Static data members
106         static const char* const typeName;
107         static const char* componentNames[];
108         static const floatScalar zero;
109         static const floatScalar one;
111     // Constructors
113         //- Construct from Istream
114         pTraits(Istream& is);
116     // Member Functions
118         operator floatScalar() const
119         {
120             return p_;
121         }
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 //template<class Cmpt>
128 //class typeOfRank<Cmpt, 0>
130 //public:
132 //    typedef Cmpt type;
133 //};
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 // Return a string representation of a floatScalar
139 word name(const floatScalar s)
141     return name(scalar(s));
144 #define MAXMINPOW(retType, type1, type2)          \
145                                                   \
146 MAXMIN(retType, type1, type2)                     \
147                                                   \
148 inline float pow(const type1 s, const type2 e)   \
149 {                                                 \
150     return ::pow(float(s), float(e));           \
154 //MAXMINPOW(float, float, float)
155 //MAXMINPOW(float, float, int)
156 //MAXMINPOW(float, int, float)
157 //MAXMINPOW(float, float, long)
158 //MAXMINPOW(float, long, float)
159 //MAXMINPOW(float, float, int)
160 //MAXMINPOW(float, int, float)
161 //MAXMINPOW(float, float, long)
162 //MAXMINPOW(float, long, float)
164 #undef MAXMINPOW
167 inline floatScalar mag(const floatScalar s)
169     return ::fabs(s);
172 inline floatScalar sign(const floatScalar s)
174     return (s >= 0)? 1: -1;
177 inline floatScalar pos(const floatScalar s)
179     return (s >= 0)? 1: 0;
182 inline floatScalar neg(const floatScalar s)
184     return (s < 0)? 1: 0;
187 inline floatScalar limit(const floatScalar s1, const floatScalar s2)
189     return (mag(s1) < mag(s2))? s1: 0.0;
192 inline floatScalar magSqr(const floatScalar s)
194     return s*s;
197 inline floatScalar sqr(const floatScalar s)
199     return s*s;
202 inline floatScalar pow3(const floatScalar s)
204     return s*s*s;
207 inline floatScalar pow4(const floatScalar s)
209     return sqr(sqr(s));
212 inline floatScalar cmptAv(const floatScalar s)
214     return s;
217 inline floatScalar cmptMag(const floatScalar s)
219     return mag(s);
222 inline floatScalar scale(const floatScalar s, const floatScalar d)
224     return s*d;
228 #define transFunc(func)            \
229 inline floatScalar func(const floatScalar s) \
230 {                                  \
231     return ::func(s);              \
234 // Standard C++ transcendental functions
235 transFunc(sqrt)
236 transFunc(exp)
237 transFunc(log)
238 transFunc(log10)
239 transFunc(sin)
240 transFunc(cos)
241 transFunc(tan)
242 transFunc(asin)
243 transFunc(acos)
244 transFunc(atan)
245 transFunc(sinh)
246 transFunc(cosh)
247 transFunc(tanh)
248 transFunc(asinh)
249 transFunc(acosh)
250 transFunc(atanh)
252 // Standard ANSI-C (but not in <cmath>) transcendental functions
253 transFunc(erf)
254 transFunc(erfc)
255 transFunc(lgamma)
256 transFunc(j0)
257 transFunc(j1)
258 transFunc(y0)
259 transFunc(y1)
261 #undef transFunc
263 // Stabilisation around zero for division
264 inline floatScalar stabilise(const floatScalar s, const floatScalar small)
266     if (s >= 0)
267     {
268         return s + small;
269     }
270     else
271     {
272         return s - small;
273     }
277 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
279 //floatScalar readScalar(Istream& is);
280 Istream& operator>>(Istream&, floatScalar&);
281 Ostream& operator<<(Ostream&, const floatScalar);
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 } // End namespace Foam
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 #endif
291 // ************************************************************************* //