FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

label.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/error.H>
00027 #include "label.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 const char* const pTraits<label>::typeName = "label";
00037 const label pTraits<label>::zero = 0;
00038 const label pTraits<label>::one = 1;
00039 const label pTraits<label>::min = labelMin;
00040 const label pTraits<label>::max = labelMax;
00041 
00042 const char* pTraits<label>::componentNames[] = { "x" };
00043 
00044 pTraits<label>::pTraits(Istream& is)
00045 {
00046     is >> p_;
00047 }
00048 
00049 
00050 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00051 
00052 // Raise one label to the power of another (overloaded function call)
00053 label pow(label a, label b)
00054 {
00055     register label ans = 1;
00056     for (register label i=0; i<b; i++)
00057     {
00058         ans *= a;
00059     }
00060 
00061 #   ifdef FULLDEBUG
00062     if (b < 0)
00063     {
00064         FatalErrorIn("pow(label a, label b)")
00065             << "negative value for b is not supported"
00066             << abort(FatalError);
00067     }
00068 #   endif
00069 
00070     return ans;
00071 }
00072 
00073 
00074 //- Return factorial(n) : 0 <= n <= 12
00075 label factorial(label n)
00076 {
00077     static label factTable[13] =
00078     {
00079         1, 1, 2, 6, 24, 120, 720, 5040, 40320,
00080         362880, 3628800, 39916800, 479001600
00081     };
00082 
00083 #   ifdef FULLDEBUG
00084     if (n > 12 && n < 0)
00085     {
00086         FatalErrorIn("factorial(label n)")
00087             << "n value out of range"
00088             << abort(FatalError);
00089     }
00090 #   endif
00091 
00092     return factTable[n];
00093 }
00094 
00095 
00096 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00097 
00098 } // End namespace Foam
00099 
00100 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines