Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2004 Sandia Corporation and Argonne National
5 : : Laboratory. Under the terms of Contract DE-AC04-94AL85000
6 : : with Sandia Corporation, the U.S. Government retains certain
7 : : rights in this software.
8 : :
9 : : This library is free software; you can redistribute it and/or
10 : : modify it under the terms of the GNU Lesser General Public
11 : : License as published by the Free Software Foundation; either
12 : : version 2.1 of the License, or (at your option) any later version.
13 : :
14 : : This library is distributed in the hope that it will be useful,
15 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : Lesser General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU Lesser General Public License
20 : : (lgpl.txt) along with this library; if not, write to the Free Software
21 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 : :
23 : : [email protected], [email protected], [email protected],
24 : : [email protected], [email protected], [email protected],
25 : : [email protected]
26 : :
27 : : ***************************************************************** */
28 : : /*!
29 : : \file Exponent.cpp
30 : : \brief
31 : :
32 : : \author Jason Kraftcheck
33 : : \date 2005-5-2
34 : : */
35 : :
36 : : #include "Exponent.hpp"
37 : :
38 : : namespace MBMesquite
39 : : {
40 : :
41 : 464 : Exponent::constMemberPtr Exponent::get_func_ptr( double exponent )
42 : : {
43 [ + + ]: 464 : if( exponent == 0.0 )
44 : 124 : return &Exponent::pow0;
45 [ + + ]: 340 : else if( exponent == 1.0 )
46 : 162 : return &Exponent::pow1;
47 [ - + ]: 178 : else if( exponent == 0.5 )
48 : 0 : return &Exponent::squareRoot;
49 [ - + ]: 178 : else if( exponent == 1. / 3. )
50 : 0 : return &Exponent::cubeRoot;
51 [ - + ]: 178 : else if( exponent == -1. / 3. )
52 : 0 : return &Exponent::invCubeRoot;
53 [ + + ]: 178 : else if( exponent == 2. / 3. )
54 : 2 : return &Exponent::powTwoThirds;
55 [ + + ]: 176 : else if( exponent == -2. / 3. )
56 : 18 : return &Exponent::invTwoThirds;
57 [ + + ]: 158 : else if( exponent == 2.0 )
58 : 4 : return &Exponent::pow2;
59 [ + + ]: 154 : else if( exponent == -1.0 )
60 : 144 : return &Exponent::inverse;
61 [ - + ]: 10 : else if( exponent == -0.5 )
62 : 0 : return &Exponent::invSquareRoot;
63 [ - + ]: 10 : else if( exponent == 1.5 )
64 : 0 : return &Exponent::powThreeHalves;
65 [ - + ]: 10 : else if( exponent == -2.0 )
66 : 0 : return &Exponent::invSquare;
67 [ + - ]: 10 : else if( std::floor( exponent ) == exponent )
68 : : {
69 [ + - ]: 10 : if( exponent > 0.0 )
70 : 10 : return &Exponent::powPositiveInt;
71 : : else
72 : 0 : return &Exponent::powNegativeInt;
73 : : }
74 : : else
75 : 0 : return &Exponent::std_pow;
76 : : }
77 : :
78 : 318 : void Exponent::set_exponent( double exponent )
79 : : {
80 : 318 : mExponent = exponent;
81 : 318 : funcPointer = get_func_ptr( exponent );
82 : 318 : }
83 : :
84 : 2763536 : double Exponent::pow0( double ) const
85 : : {
86 : 2763536 : return 1.0;
87 : : }
88 : 17535993 : double Exponent::pow1( double x ) const
89 : : {
90 : 17535993 : return x;
91 : : }
92 : 90896 : double Exponent::pow2( double x ) const
93 : : {
94 : 90896 : return x * x;
95 : : }
96 : 0 : double Exponent::squareRoot( double x ) const
97 : : {
98 : 0 : return std::sqrt( x );
99 : : }
100 : 0 : double Exponent::cubeRoot( double x ) const
101 : : {
102 : 0 : return MBMesquite::cbrt( x );
103 : : }
104 : 0 : double Exponent::invCubeRoot( double x ) const
105 : : {
106 : 0 : return 1.0 / MBMesquite::cbrt( x );
107 : : }
108 : 1615 : double Exponent::powTwoThirds( double x ) const
109 : : {
110 : 1615 : return MBMesquite::cbrt_sqr( x );
111 : : }
112 : 612336 : double Exponent::invTwoThirds( double x ) const
113 : : {
114 : 612336 : return 1.0 / MBMesquite::cbrt_sqr( x );
115 : : }
116 : 0 : double Exponent::std_pow( double x ) const
117 : : {
118 : 0 : return std::pow( x, mExponent );
119 : : }
120 : 75232 : double Exponent::inverse( double x ) const
121 : : {
122 : 75232 : return 1.0 / x;
123 : : }
124 : 0 : double Exponent::invSquareRoot( double x ) const
125 : : {
126 : 0 : return 1.0 / std::sqrt( x );
127 : : }
128 : 0 : double Exponent::powThreeHalves( double x ) const
129 : : {
130 : 0 : return x * x * x / std::sqrt( x );
131 : : }
132 : 0 : double Exponent::invSquare( double x ) const
133 : : {
134 : 0 : return 1.0 / ( x * x );
135 : : }
136 : :
137 : 1190319 : double Exponent::powPositiveInt( double x ) const
138 : : {
139 : 1190319 : double result = x;
140 [ + + ]: 8359143 : for( int i = (int)mExponent - 1; i > 0; --i )
141 : 7168824 : result *= x;
142 : 1190319 : return result;
143 : : }
144 : :
145 : 0 : double Exponent::powNegativeInt( double x ) const
146 : : {
147 : 0 : double result = x;
148 [ # # ]: 0 : for( int i = ( -(int)mExponent ) - 1; i > 0; --i )
149 : 0 : result *= x;
150 : 0 : return 1.0 / result;
151 : : }
152 : :
153 : : } // namespace MBMesquite
|