scalarI.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) 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 \*---------------------------------------------------------------------------*/
25 
26 #include "scalar.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 inline Foam::scalar Foam::integerPow(const scalar x, const label e)
31 {
32  if (e == 0)
33  {
34  return 1;
35  }
36 
37  scalar xx = e > 0 ? x : 1/x;
38 
39  scalar y = 1;
40 
41  for (label i = e; i != 0; i /= 2)
42  {
43  if (i % 2)
44  {
45  y *= xx;
46  }
47 
48  xx *= xx;
49  }
50 
51  return y;
52 }
53 
54 
55 inline Foam::scalar Foam::integerRoot(const scalar x, const label e)
56 {
57  switch (e)
58  {
59  case -4: return 1/pow025(x);
60  case -3: return 1/cbrt(x);
61  case -2: return 1/sqrt(x);
62  case -1: return 1/x;
63  case 0: return NaN;
64  case 1: return x;
65  case 2: return sqrt(x);
66  case 3: return cbrt(x);
67  case 4: return pow025(x);
68  }
69 
70  return pow(x, scalar(1)/e);
71 }
72 
73 
74 // ************************************************************************* //
scalar y
const dimensionedScalar e
Elementary charge.
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
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
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)