File tree Expand file tree Collapse file tree 1 file changed +29
-5
lines changed
Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Original file line number Diff line number Diff line change 2828namespace internal
2929{
3030
31+ // see https://en.wikipedia.org/wiki/Euler%27s_continued_fraction_formula
32+
33+ #if __cplusplus >= 201402L // C++14 version
34+
35+ template <typename T>
36+ constexpr
37+ T
38+ exp_cf_recur (const T x, const int depth_end)
39+ noexcept
40+ {
41+ int depth = GCEM_EXP_MAX_ITER_SMALL - 1 ;
42+ T res = T (1 );
43+
44+ while (depth > depth_end - 1 ) {
45+ res = T (1 ) + x/T (depth - 1 ) - x/depth/res;
46+
47+ --depth;
48+ }
49+
50+ return res;
51+ }
52+
53+ #else // C++11 version
54+
3155template <typename T>
3256constexpr
3357T
@@ -36,20 +60,20 @@ noexcept
3660{
3761 return ( depth < GCEM_EXP_MAX_ITER_SMALL ? \
3862 // if
39- depth == 1 ? \
40- T (1 ) - x/exp_cf_recur (x,depth+1 ) :
41- T (1 ) + x/T (depth - 1 ) - x/depth/exp_cf_recur (x,depth+1 ) :
63+ T (1 ) + x/T (depth - 1 ) - x/depth/exp_cf_recur (x,depth+1 ) :
4264 // else
4365 T (1 ) );
4466}
4567
68+ #endif
69+
4670template <typename T>
4771constexpr
4872T
4973exp_cf (const T x)
5074noexcept
5175{
52- return ( T (1 )/ exp_cf_recur (x,1 ) );
76+ return ( T (1 ) / ( T ( 1 ) - x / exp_cf_recur (x,2 ) ) );
5377}
5478
5579template <typename T>
@@ -72,7 +96,7 @@ noexcept
7296 //
7397 is_neginf (x) ? \
7498 T (0 ) :
75- //
99+ // indistinguishable from zero
76100 GCLIM<T>::min () > abs (x) ? \
77101 T (1 ) :
78102 //
You can’t perform that action at this time.
0 commit comments