| 2066 | */ |
| 2067 | template<class ValueType> |
| 2068 | ValueType Root(ValueType x, const ValueType & index, ErrorCode * err = 0) |
| 2069 | { |
| 2070 | using namespace auxiliaryfunctions; |
| 2071 | |
| 2072 | if( x.IsNan() || index.IsNan() ) |
| 2073 | { |
| 2074 | if( err ) |
| 2075 | *err = err_improper_argument; |
| 2076 | |
| 2077 | x.SetNan(); |
| 2078 | |
| 2079 | return x; |
| 2080 | } |
| 2081 | |
| 2082 | if( RootCheckIndexSign(x, index, err) ) return x; |
| 2083 | if( RootCheckIndexZero(x, index, err) ) return x; |
| 2084 | if( RootCheckIndexOne ( index, err) ) return x; |
| 2085 | if( RootCheckIndexTwo (x, index, err) ) return x; |
| 2086 | if( RootCheckIndexFrac(x, index, err) ) return x; |
| 2087 | if( RootCheckXZero (x, err) ) return x; |
| 2088 | |
| 2089 | // index integer and index!=0 |
| 2090 | // x!=0 |
| 2091 | |
| 2092 | ValueType old_x(x); |
| 2093 | bool change_sign; |
| 2094 | |
| 2095 | if( RootCheckIndex(x, index, err, &change_sign ) ) return x; |
| 2096 | |
| 2097 | ValueType temp; |
| 2098 | uint c = 0; |
| 2099 | |
| 2100 | // we're using the formula: root(x ; n) = exp( ln(x) / n ) |
| 2101 | c += temp.Ln(x); |
| 2102 | c += temp.Div(index); |
| 2103 | c += x.Exp(temp); |
| 2104 | |
| 2105 | if( change_sign ) |
| 2106 | { |
| 2107 | // x is different from zero |
| 2108 | x.SetSign(); |
| 2109 | } |
| 2110 | |
| 2111 | c += RootCorrectInteger(old_x, x, index); |
| 2112 | |
| 2113 | if( err ) |
| 2114 | *err = c ? err_overflow : err_ok; |
| 2115 | |
| 2116 | return x; |
| 2117 | } |
| 2118 | |
| 2119 | |
| 2120 |
nothing calls this directly
no test coverage detected