OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "error.H"
00028 #include "label.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 const char* const pTraits<label>::typeName = "label";
00038 const label pTraits<label>::zero = 0;
00039 const label pTraits<label>::one = 1;
00040 const label pTraits<label>::min = labelMin;
00041 const label pTraits<label>::max = labelMax;
00042 
00043 const char* pTraits<label>::componentNames[] = { "x" };
00044 
00045 pTraits<label>::pTraits(Istream& is)
00046 {
00047     is >> p_;
00048 }
00049 
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 // Raise one label to the power of another (overloaded function call)
00054 label pow(label a, label b)
00055 {
00056     register label ans = 1;
00057     for (register label i=0; i<b; i++)
00058     {
00059         ans *= a;
00060     }
00061 
00062 #   ifdef FULLDEBUG
00063     if (b < 0)
00064     {
00065         FatalErrorIn("pow(label a, label b)")
00066             << "negative value for b is not supported"
00067             << abort(FatalError);
00068     }
00069 #   endif
00070 
00071     return ans;
00072 }
00073 
00074 
00075 //- Return factorial(n) : 0 <= n <= 12
00076 label factorial(label n)
00077 {
00078     static label factTable[13] =
00079     {
00080         1, 1, 2, 6, 24, 120, 720, 5040, 40320,
00081         362880, 3628800, 39916800, 479001600
00082     };
00083 
00084 #   ifdef FULLDEBUG
00085     if (n > 12 && n < 0)
00086     {
00087         FatalErrorIn("factorial(label n)")
00088             << "n value out of range"
00089             << abort(FatalError);
00090     }
00091 #   endif
00092 
00093     return factTable[n];
00094 }
00095 
00096 
00097 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00098 
00099 } // End namespace Foam
00100 
00101 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd