Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
primitives
ints
label
label.C
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
========= |
3
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4
\\ / O peration |
5
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 <
OpenFOAM/error.H
>
27
#include "
label.H
"
28
29
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30
31
namespace
Foam
32
{
33
34
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35
36
const
char
*
const
pTraits<label>::typeName
=
"label"
;
37
const
label
pTraits<label>::zero
= 0;
38
const
label
pTraits<label>::one
= 1;
39
const
label
pTraits<label>::min
= labelMin;
40
const
label
pTraits<label>::max
= labelMax;
41
42
const
char
*
pTraits<label>::componentNames
[] = {
"x"
};
43
44
pTraits<label>::pTraits
(
Istream
& is)
45
{
46
is >> p_;
47
}
48
49
50
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52
// Raise one label to the power of another (overloaded function call)
53
label
pow
(label a, label
b
)
54
{
55
register
label ans = 1;
56
for
(
register
label i=0; i<
b
; i++)
57
{
58
ans *= a;
59
}
60
61
# ifdef FULLDEBUG
62
if
(b < 0)
63
{
64
FatalErrorIn
(
"pow(label a, label b)"
)
65
<<
"negative value for b is not supported"
66
<<
abort
(
FatalError
);
67
}
68
# endif
69
70
return
ans;
71
}
72
73
74
//- Return factorial(n) : 0 <= n <= 12
75
label
factorial
(label n)
76
{
77
static
label factTable[13] =
78
{
79
1, 1, 2, 6, 24, 120, 720, 5040, 40320,
80
362880, 3628800, 39916800, 479001600
81
};
82
83
# ifdef FULLDEBUG
84
if
(n > 12 && n < 0)
85
{
86
FatalErrorIn
(
"factorial(label n)"
)
87
<<
"n value out of range"
88
<<
abort
(
FatalError
);
89
}
90
# endif
91
92
return
factTable[n];
93
}
94
95
96
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97
98
}
// End namespace Foam
99
100
// ************************ vim: set sw=4 sts=4 et: ************************ //