bigdecimal-math_r 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +13 -0
- data/changelog.md +24 -0
- data/ext/bigdecimal/math_r/algofunc.h +203 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/check_precise.h +12 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/infinity.h +6 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/minus_infinity.h +5 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/minus_one.h +6 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/minus_zero.h +6 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/nan.h +6 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/one.h +6 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/sign.h +10 -0
- data/ext/bigdecimal/math_r/api/bigdecimal/zero.h +6 -0
- data/ext/bigdecimal/math_r/api/bigmath/api_call1.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/api_call2.h +6 -0
- data/ext/bigdecimal/math_r/api/bigmath/atan.h +7 -0
- data/ext/bigdecimal/math_r/api/bigmath/atan_adopt.h +42 -0
- data/ext/bigdecimal/math_r/api/bigmath/cabs.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/carg.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/cexp.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/clog.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const.h +39 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_e.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_log10.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_log2.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_log_pi.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_pi.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_sqrt2.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/const_sqrt3.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/cpow.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/csqrt.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/degree_sparg.h +199 -0
- data/ext/bigdecimal/math_r/api/bigmath/escalb.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/exp.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/expxt.h +18 -0
- data/ext/bigdecimal/math_r/api/bigmath/hypot.h +10 -0
- data/ext/bigdecimal/math_r/api/bigmath/ipow.h +14 -0
- data/ext/bigdecimal/math_r/api/bigmath/l2norm.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/log.h +7 -0
- data/ext/bigdecimal/math_r/api/bigmath/pow.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/quadrant.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/sincos.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/sqrt.h +5 -0
- data/ext/bigdecimal/math_r/api/bigmath/to_rad.h +41 -0
- data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal.h +6 -0
- data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal1.h +6 -0
- data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal_flo.h +9 -0
- data/ext/bigdecimal/math_r/api/kernel/rb_ImaginaryZ.h +8 -0
- data/ext/bigdecimal/math_r/api/numanalysis/condition_p.h +26 -0
- data/ext/bigdecimal/math_r/api/numanalysis/make_n.h +9 -0
- data/ext/bigdecimal/math_r/api/numeric/abs.h +7 -0
- data/ext/bigdecimal/math_r/api/numeric/canonicalize.h +140 -0
- data/ext/bigdecimal/math_r/api/numeric/cmpeql.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/equal_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/finite_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/imag.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/infinite_p.h +7 -0
- data/ext/bigdecimal/math_r/api/numeric/nan_p.h +5 -0
- data/ext/bigdecimal/math_r/api/numeric/negative_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/nonzero_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/notequal_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/numeric_p.h +5 -0
- data/ext/bigdecimal/math_r/api/numeric/positive_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/real.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/real_p.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/round.h +56 -0
- data/ext/bigdecimal/math_r/api/numeric/uminus.h +6 -0
- data/ext/bigdecimal/math_r/api/numeric/zero_p.h +6 -0
- data/ext/bigdecimal/math_r/api.c +13 -0
- data/ext/bigdecimal/math_r/api.h +69 -0
- data/ext/bigdecimal/math_r/const.c +186 -0
- data/ext/bigdecimal/math_r/decl.h +203 -0
- data/ext/bigdecimal/math_r/edf.c +180 -0
- data/ext/bigdecimal/math_r/erf.c +80 -0
- data/ext/bigdecimal/math_r/euler_f.c +572 -0
- data/ext/bigdecimal/math_r/exp.c +72 -0
- data/ext/bigdecimal/math_r/extconf.rb +185 -0
- data/ext/bigdecimal/math_r/gamma_r.c +251 -0
- data/ext/bigdecimal/math_r/hyperb.c +172 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/E/ser.h +22 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG10/ser.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG2/BBP2002.h +36 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG_PI/builtin.h +7 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/PI/machin.h +48 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/SQRT2/builtin.h +5 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/SQRT3/builtin.h +5 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/branch.h +25 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/edom.h +15 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/logrep.h +19 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/ser.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/branch.h +19 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/edom.h +17 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/logrep.h +14 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acot/branch.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acot/logrep.h +13 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/branch.h +20 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/edom.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/logrep.h +33 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/branch.h +21 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/edom.h +20 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/logrep.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsch/branch.h +25 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsch/logrep.h +25 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/branch.h +22 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/edom.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/logrep.h +21 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/branch.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/edom.h +19 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/logrep.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/branch.h +22 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/edom.h +20 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/logrep.h +15 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/ser.h +32 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/branch.h +26 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/logrep.h +24 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/ser.h +48 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/branch.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/logrep.h +14 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_euler.h +84 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_usual.h +41 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/branch.h +24 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/edom.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/logrep.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/ser.h +33 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cabs/formula.h +8 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacos/branch.h +38 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacos/logrep.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacosh/branch.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacosh/logrep.h +17 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacot/branch.h +39 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacot/logrep.h +17 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacoth/branch.h +29 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacoth/logrep.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsc/branch.h +28 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsc/logrep.h +19 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsch/branch.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsch/logrep.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/carg/formula.h +8 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casec/branch.h +29 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casec/logrep.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casech/branch.h +38 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casech/logrep.h +9 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casin/branch.h +35 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casin/logrep.h +14 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casinh/branch.h +59 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casinh/logrep.h +13 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/catan/branch.h +46 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/catan/logrep.h +17 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/catanh/branch.h +26 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/catanh/logrep.h +10 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccbrt/formula.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccos/branch.h +41 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccos/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccosh/branch.h +37 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccosh/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccot/branch.h +46 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccot/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccoth/branch.h +43 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccoth/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsc/branch.h +42 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsc/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsch/branch.h +38 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsch/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp/branch.h +42 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp/eulerf.h +21 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp2/branch.h +42 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp2/eulerf.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/clog/branch.h +54 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/clog/formula.h +13 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/clog10/formula.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/clog1p/branch.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/clog2/formula.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/branch.h +21 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/ser.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/branch.h +22 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/formula.h +30 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/ser.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/branch.h +28 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/ser.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/branch.h +23 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/formula.h +30 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/ser.h +13 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cpow/formula.h +20 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/branch.h +28 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/ser.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/branch.h +23 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/formula.h +31 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/ser.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csec/branch.h +42 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csec/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csech/branch.h +38 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csech/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csin/branch.h +44 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csin/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csinh/branch.h +41 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csinh/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/csqrt/formula.h +66 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ctan/branch.h +46 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ctan/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ctanh/branch.h +43 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ctanh/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cuberoot/newton.h +42 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/algo911.h +41 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/branch.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/cf.h +51 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/ser_inf.h +53 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/ser_zero.h +45 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/algo911.h +27 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/branch.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/cf.h +49 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/escalb/edf.h +87 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/branch.h +29 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/builtin.h +6 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/edf.h +23 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/exp2/branch.h +29 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/exp2/edf.h +19 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/expxt/edf.h +31 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/f_euler/formula.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/branch.h +25 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/l2norm.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/mmm.h +38 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ipow/edf.h +33 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/l2norm/formula.h +48 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log/branch.h +40 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log/builtin.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log/edf.h +10 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log/edom.h +10 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log/mercator.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log/ser_okumura.h +57 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/branch.h +40 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/edf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/mercator.h +35 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/branch.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/p_adic.h +37 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/ser_mercator.h +35 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/branch.h +40 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/edf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/mercator.h +35 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/logxt/edf.h +33 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/pow/formula.h +30 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/quadrant/formula.h +352 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm10/edf.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm2/edf.h +34 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/branch.h +27 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/ser.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/branch.h +21 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/formula.h +25 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/ser.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/branch.h +23 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/ser.h +13 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sincos/ser.h +50 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/branch.h +23 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/formula.h +26 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/ser.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sinhcosh/ser.h +70 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/branch.h +16 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/builtin.h +12 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/edom.h +9 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/newton.h +36 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/branch.h +26 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/ser.h +18 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/branch.h +23 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/eulerf.h +11 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/formula.h +27 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/ser.h +14 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/trig/f_euler.h +290 -0
- data/ext/bigdecimal/math_r/log.c +256 -0
- data/ext/bigdecimal/math_r/logrep.c +537 -0
- data/ext/bigdecimal/math_r/math_r/bigdecimal.h +30 -0
- data/ext/bigdecimal/math_r/math_r/bigmath.h +61 -0
- data/ext/bigdecimal/math_r/math_r/bigmath_r.h +9 -0
- data/ext/bigdecimal/math_r/math_r/ext_extern.h +18 -0
- data/ext/bigdecimal/math_r/math_r/globals.h +71 -0
- data/ext/bigdecimal/math_r/math_r/numdiff.h +18 -0
- data/ext/bigdecimal/math_r/math_r/numeric.h +63 -0
- data/ext/bigdecimal/math_r/math_r.c +130 -0
- data/ext/bigdecimal/math_r/nucomp.c +158 -0
- data/ext/bigdecimal/math_r/overrides.c +91 -0
- data/ext/bigdecimal/math_r/power.c +207 -0
- data/ext/bigdecimal/math_r/solver.c +1516 -0
- data/ext/bigdecimal/math_r/trig.c +205 -0
- data/lib/bigdecimal/math_r/const/EulerGamma_engel.rb +46 -0
- data/lib/bigdecimal/math_r/const/LOG2_bbp2007.rb +39 -0
- data/lib/bigdecimal/math_r/const/PI_chudnovsky.rb +59 -0
- data/lib/bigdecimal/math_r/const/PI_euler.rb +40 -0
- data/lib/bigdecimal/math_r/const/PI_ramanujan1.rb +45 -0
- data/lib/bigdecimal/math_r/const/PI_ramanujan2.rb +46 -0
- data/lib/bigdecimal/math_r/const/b053977/b053977.txt +306 -0
- data/lib/bigdecimal/math_r/version.rb +7 -0
- data/lib/bigdecimal/math_r.rb +12 -0
- data/lib/bigdecimal/math_r.so +0 -0
- data/sig/bigdecimal/math_r.rbs +6 -0
- metadata +393 -0
@@ -0,0 +1,205 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
trig.c -- Trigonometric Function
|
3
|
+
|
4
|
+
Author: tribusonz
|
5
|
+
Licence: MIT
|
6
|
+
*******************************************************************************/
|
7
|
+
#include <ruby.h>
|
8
|
+
#include "math_r/globals.h"
|
9
|
+
#include "math_r/bigmath_r.h"
|
10
|
+
#include "decl.h"
|
11
|
+
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Computes at once sine and cosine of +x+.
|
15
|
+
*
|
16
|
+
* @param x [Numeric] Numerical argument
|
17
|
+
* @param prec [Integer] Arbitrary precision
|
18
|
+
* @return [Array] Real solutions [sin(x), cos(x)]
|
19
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
20
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
21
|
+
* @example
|
22
|
+
* BigMathR::Trig.sincos(1, 20)
|
23
|
+
* #=> [0.84147098480789650665e0, 0.5403023058681397174e0]
|
24
|
+
* @since 0.1.0
|
25
|
+
*/
|
26
|
+
static VALUE
|
27
|
+
__impl_trig_sincos(VALUE unused_obj, VALUE x, VALUE prec)
|
28
|
+
{
|
29
|
+
VALUE sin, cos, t;
|
30
|
+
rb_check_precise(prec);
|
31
|
+
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
32
|
+
x = rb_bigmath_to_rad(x, prec, &t);
|
33
|
+
if (-1 == rb_bigmath_degree_sparg(t, prec, &sin, &cos))
|
34
|
+
rb_bigmath_sincos(x, prec, &sin, &cos);
|
35
|
+
sin = rb_num_round(sin, prec);
|
36
|
+
cos = rb_num_round(cos, prec);
|
37
|
+
return rb_assoc_new(sin, cos);
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Computes sine of +x+.
|
43
|
+
* <br>
|
44
|
+
* +x+ gives in radian.
|
45
|
+
*
|
46
|
+
* @param x [Numeric] Numerical argument
|
47
|
+
* @param prec [Integer] Arbitrary precision
|
48
|
+
* @return [BigDecimal] Real solution
|
49
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
50
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
51
|
+
* @example
|
52
|
+
* BigMathR::Trig.sin(1, 20)
|
53
|
+
* #=> 0.84147098480789650665e0
|
54
|
+
* @since 0.1.0
|
55
|
+
*/
|
56
|
+
static VALUE
|
57
|
+
__impl_trig_sin(VALUE unused_obj, VALUE x, VALUE prec)
|
58
|
+
{
|
59
|
+
return sin_branch(x, prec, sin_ser);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Computes cosine of +x+.
|
65
|
+
* <br>
|
66
|
+
* +x+ gives in radian.
|
67
|
+
*
|
68
|
+
* @param x [Numeric] Numerical argument
|
69
|
+
* @param prec [Integer] Arbitrary precision
|
70
|
+
* @return [BigDecimal] Real solution
|
71
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
72
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
73
|
+
* @example
|
74
|
+
* BigMathR::Trig.cos(1, 20)
|
75
|
+
* #=> 0.5403023058681397174e0
|
76
|
+
* @since 0.1.0
|
77
|
+
*/
|
78
|
+
static VALUE
|
79
|
+
__impl_trig_cos(VALUE unused_obj, VALUE x, VALUE prec)
|
80
|
+
{
|
81
|
+
return cos_branch(x, prec, cos_ser);
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Computes tangent of +x+.
|
87
|
+
* <br>
|
88
|
+
* +x+ gives in radian.
|
89
|
+
*
|
90
|
+
* @param x [Numeric] Numerical argument
|
91
|
+
* @param prec [Integer] Arbitrary precision
|
92
|
+
* @return [BigDecimal] Real solution
|
93
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
94
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
95
|
+
* @example
|
96
|
+
* BigMathR::Trig.tan(1, 20)
|
97
|
+
* #=> 0.15574077246549022305e1
|
98
|
+
* @since 0.1.0
|
99
|
+
*/
|
100
|
+
static VALUE
|
101
|
+
__impl_trig_tan(VALUE unused_obj, VALUE x, VALUE prec)
|
102
|
+
{
|
103
|
+
return tan_branch(x, prec, tan_ser);
|
104
|
+
}
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Computes cosecant of +x+.
|
108
|
+
* <br>
|
109
|
+
* +x+ gives in radian.
|
110
|
+
*
|
111
|
+
* @param x [Numeric] Numerical argument
|
112
|
+
* @param prec [Integer] Arbitrary precision
|
113
|
+
* @return [BigDecimal] Real solution
|
114
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
115
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
116
|
+
* @example
|
117
|
+
* BigMathR::Trig.csc(1, 20)
|
118
|
+
* #=> 0.11883951057781212163e1
|
119
|
+
* @since 0.1.0
|
120
|
+
*/
|
121
|
+
static VALUE
|
122
|
+
__impl_trig_csc(VALUE unused_obj, VALUE x, VALUE prec)
|
123
|
+
{
|
124
|
+
return csc_branch(x, prec, csc_ser);
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Computes secant of +x+.
|
129
|
+
* <br>
|
130
|
+
* +x+ gives in radian.
|
131
|
+
*
|
132
|
+
* @param x [Numeric] Numerical argument
|
133
|
+
* @param prec [Integer] Arbitrary precision
|
134
|
+
* @return [BigDecimal] Real solution
|
135
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
136
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
137
|
+
* @example
|
138
|
+
* BigMathR::Trig.sec(1, 20)
|
139
|
+
* #=> 0.18508157176809256179e1
|
140
|
+
* @since 0.1.0
|
141
|
+
*/
|
142
|
+
static VALUE
|
143
|
+
__impl_trig_sec(VALUE unused_obj, VALUE x, VALUE prec)
|
144
|
+
{
|
145
|
+
return sec_branch(x, prec, sec_ser);
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Computes cotangent of +x+.
|
151
|
+
* <br>
|
152
|
+
* +x+ gives in radian.
|
153
|
+
*
|
154
|
+
* @param x [Numeric] Numerical argument
|
155
|
+
* @param prec [Integer] Arbitrary precision
|
156
|
+
* @return [BigDecimal] Real solution
|
157
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
158
|
+
* @raise [TypeError] Occurs when +x+ is not a numeric class.
|
159
|
+
* @example
|
160
|
+
* BigMathR::Trig.cot(1, 20)
|
161
|
+
* #=> 0.64209261593433070301e0
|
162
|
+
* @since 0.1.0
|
163
|
+
*/
|
164
|
+
static VALUE
|
165
|
+
__impl_trig_cot(VALUE unused_obj, VALUE x, VALUE prec)
|
166
|
+
{
|
167
|
+
return cot_branch(x, prec, cot_ser);
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Document-module: BigMathR::Trig
|
172
|
+
*
|
173
|
+
* A module that provide the trigonometric functions.
|
174
|
+
* It is used internally.
|
175
|
+
* <br>
|
176
|
+
* All module functions are implemented by +:sincos+.
|
177
|
+
* <br>
|
178
|
+
* == Synopsis
|
179
|
+
* The function names defined are the same as those in the C/C++ standard.
|
180
|
+
* <br>
|
181
|
+
* - Sine: +:sin+ <br>
|
182
|
+
* - Cosine: +:cos+ <br>
|
183
|
+
* - Tangent: +:tan+ <br>
|
184
|
+
* Follow, those reciprocals of not defined in C/C++ standard.
|
185
|
+
* <br>
|
186
|
+
* - Cosecant: +:csc+ <br>
|
187
|
+
* - Secant: +:sec+ <br>
|
188
|
+
* - Cotangent: +:cot+ <br>
|
189
|
+
* The following are GNU extensions:
|
190
|
+
* <br>
|
191
|
+
* - sincos(): +:sincos+ <br>
|
192
|
+
* Reference::
|
193
|
+
* Kiso kara hatten made Sankaku kansuu (Japanese) - Michimasa Kobayashi (Beret Shuppan)
|
194
|
+
*/
|
195
|
+
void
|
196
|
+
InitVM_Trig(void)
|
197
|
+
{
|
198
|
+
rb_define_module_function(rb_mTrig, "sincos", __impl_trig_sincos, 2);
|
199
|
+
rb_define_module_function(rb_mTrig, "sin", __impl_trig_sin, 2);
|
200
|
+
rb_define_module_function(rb_mTrig, "cos", __impl_trig_cos, 2);
|
201
|
+
rb_define_module_function(rb_mTrig, "tan", __impl_trig_tan, 2);
|
202
|
+
rb_define_module_function(rb_mTrig, "csc", __impl_trig_csc, 2);
|
203
|
+
rb_define_module_function(rb_mTrig, "sec", __impl_trig_sec, 2);
|
204
|
+
rb_define_module_function(rb_mTrig, "cot", __impl_trig_cot, 2);
|
205
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
module BigMathR
|
6
|
+
module Const
|
7
|
+
module EulerGamma
|
8
|
+
module_function
|
9
|
+
# Implement by Engel expansion.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# BigMathR::Const::EulerGamma.engel(20)
|
13
|
+
# #=> 0.57721566490153286061e0
|
14
|
+
# @param prec [Integer] Arbitrary precision
|
15
|
+
# @return [BigDecimal] Euler-Mascheroni constant gamma
|
16
|
+
# @raise [TypeError] not an Integer
|
17
|
+
# @raise [RangeError] Zero or negative precision
|
18
|
+
# @see https://oeis.org/A053977
|
19
|
+
def engel(prec)
|
20
|
+
raise TypeError, "precision must be an Integer" unless prec.class == Integer
|
21
|
+
raise RangeError, "Zero or negative precision" if prec <= 0
|
22
|
+
n = BigDecimal.double_fig + prec
|
23
|
+
|
24
|
+
f = File.open(__dir__ + '/b053977/b053977.txt', 'r')
|
25
|
+
g = 1
|
26
|
+
fread = -> do
|
27
|
+
raise "there is no more list" if f.eof?
|
28
|
+
_, coef = f.readline.chomp.split(' ');
|
29
|
+
raise "expansion maximum reached" if coef.nil?
|
30
|
+
g *= coef.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
d = BigDecimal(1)
|
34
|
+
y = BigDecimal(0)
|
35
|
+
|
36
|
+
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
37
|
+
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
38
|
+
d = BigDecimal(Rational(1, fread.call), m)
|
39
|
+
y += d
|
40
|
+
end
|
41
|
+
y.round(prec)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BigMathR
|
4
|
+
module Const
|
5
|
+
module LOG2
|
6
|
+
module_function
|
7
|
+
# Implement by BBP's formula (Bailey et al. 2007)
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# BigMathR::Const::LOG2.bbp2007(20)
|
11
|
+
# #=> 0.69314718055994530942e0
|
12
|
+
# @param prec [Integer] Arbitrary precision
|
13
|
+
# @return [BigDecimal] Natural logarithm of 2
|
14
|
+
# @raise [TypeError] not an Integer
|
15
|
+
# @raise [RangeError] Zero or negative precision
|
16
|
+
def bbp2007(prec)
|
17
|
+
raise TypeError, "precision must be an Integer" unless prec.class == Integer
|
18
|
+
raise RangeError, "Zero or negative precision" if prec <= 0
|
19
|
+
|
20
|
+
n = prec + BigDecimal.double_fig
|
21
|
+
one = BigDecimal(1)
|
22
|
+
two = BigDecimal(2)
|
23
|
+
i1 = one
|
24
|
+
i2 = two
|
25
|
+
d = one
|
26
|
+
y = BigDecimal(0)
|
27
|
+
|
28
|
+
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
29
|
+
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
30
|
+
d = one.div(i1 * i2, m)
|
31
|
+
y = y + d
|
32
|
+
i1 += one
|
33
|
+
i2 *= two
|
34
|
+
end
|
35
|
+
y.round(prec)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal/math'
|
4
|
+
|
5
|
+
module BigMathR
|
6
|
+
module Const
|
7
|
+
module PI
|
8
|
+
module_function
|
9
|
+
# Implement by Chudnovsky's formula
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# BigMathR::Const::PI.chudnovsky(20)
|
13
|
+
# #=> 0.31415926535897932385e1
|
14
|
+
# @param prec [Integer] Arbitrary precision
|
15
|
+
# @return [BigDecimal] Constant PI
|
16
|
+
# @raise [TypeError] not an Integer
|
17
|
+
# @raise [RangeError] Zero or negative precision
|
18
|
+
def chudnovsky(prec)
|
19
|
+
raise TypeError, "precision must be an Integer" unless prec.class == Integer
|
20
|
+
raise RangeError, "Zero or negative precision" if prec <= 0
|
21
|
+
|
22
|
+
zero = BigDecimal(0)
|
23
|
+
one = BigDecimal(1)
|
24
|
+
|
25
|
+
n = prec + BigDecimal.double_fig
|
26
|
+
|
27
|
+
m1_640320_3 = BigDecimal(-1/262537412640768000r, n)
|
28
|
+
p90856689_711822400 = BigDecimal(90856689/711822400r, n)
|
29
|
+
p90856689_711822400 *= BigDecimal(10005).sqrt(n)
|
30
|
+
|
31
|
+
_C = one
|
32
|
+
_AB = BigDecimal(13591409/545140134r, n)
|
33
|
+
_F = 1r
|
34
|
+
|
35
|
+
d = one
|
36
|
+
y = zero
|
37
|
+
|
38
|
+
i = 0
|
39
|
+
|
40
|
+
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
41
|
+
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
42
|
+
|
43
|
+
d = BigDecimal(_F, m).mult(_AB * _C, m)
|
44
|
+
y = y + d
|
45
|
+
|
46
|
+
_AB += one
|
47
|
+
_C *= m1_640320_3
|
48
|
+
i = i.succ
|
49
|
+
(6 * i - 5).step(6 * i) {|k| _F *= k}
|
50
|
+
(3 * i - 2).step(3 * i) {|k| _F /= k}
|
51
|
+
3.times { _F /= i }
|
52
|
+
end
|
53
|
+
|
54
|
+
y = y.mult(p90856689_711822400, n)
|
55
|
+
one.div(y, prec)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal/math'
|
4
|
+
|
5
|
+
module BigMathR
|
6
|
+
module Const
|
7
|
+
module PI
|
8
|
+
module_function
|
9
|
+
# Implement by Euler's formula.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# BigMathR::Const::PI.euler(20)
|
13
|
+
# #=> 0.31415926535897932385e1
|
14
|
+
# @param prec [Integer] Arbitrary precision
|
15
|
+
# @return [BigDecimal] Constant PI
|
16
|
+
# @raise [TypeError] not an Integer
|
17
|
+
# @raise [RangeError] Zero or negative precision
|
18
|
+
def euler(prec)
|
19
|
+
raise TypeError, "precision must be an Integer" unless prec.class == Integer
|
20
|
+
raise RangeError, "Zero or negative precision" if prec <= 0
|
21
|
+
n = BigDecimal.double_fig + prec
|
22
|
+
one = BigDecimal(1)
|
23
|
+
two = BigDecimal(2)
|
24
|
+
s = BigDecimal(0)
|
25
|
+
t = one
|
26
|
+
t1 = BigDecimal(0)
|
27
|
+
t2 = one
|
28
|
+
n = prec + BigDecimal.double_fig
|
29
|
+
while t.nonzero? && ((m = n - (s.exponent - t.exponent).abs) > 0)
|
30
|
+
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
31
|
+
s = s + t
|
32
|
+
t1 = t1 + one; t = t.mult(t1, m)
|
33
|
+
t2 = t2 + two; t = t.div(t2, m)
|
34
|
+
end
|
35
|
+
two.mult(s, prec)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal/math'
|
4
|
+
|
5
|
+
module BigMathR
|
6
|
+
module Const
|
7
|
+
module PI
|
8
|
+
module_function
|
9
|
+
# Implement by Ramanujan's formula.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# BigMathR::Const::PI.ramanujan1(20)
|
13
|
+
# #=> 0.31415926535897932385e1
|
14
|
+
# @param prec [Integer] Arbitrary precision
|
15
|
+
# @return [BigDecimal] Constant PI
|
16
|
+
# @raise [TypeError] not an Integer
|
17
|
+
# @raise [RangeError] Zero or negative precision
|
18
|
+
def ramanujan1(prec)
|
19
|
+
raise TypeError, "precision must be an Integer" unless prec.class == Integer
|
20
|
+
raise RangeError, "Zero or negative precision" if prec <= 0
|
21
|
+
n = BigDecimal.double_fig + prec
|
22
|
+
|
23
|
+
i = 0
|
24
|
+
r = 1/9801r
|
25
|
+
k = 1103
|
26
|
+
|
27
|
+
d = BigDecimal(1)
|
28
|
+
y = BigDecimal(0)
|
29
|
+
|
30
|
+
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
31
|
+
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
32
|
+
d = BigDecimal(r * k, m)
|
33
|
+
y = y + d
|
34
|
+
i = i.succ
|
35
|
+
k += 26390
|
36
|
+
r *= (2 * i - 1) * (4 * i - 3) * (4 * i - 1)
|
37
|
+
r /= 96059601
|
38
|
+
r /= 32
|
39
|
+
3.times { r /= i }
|
40
|
+
end
|
41
|
+
BigDecimal(2).sqrt(n).div(y * BigDecimal(4), prec)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal/math'
|
4
|
+
|
5
|
+
module BigMathR
|
6
|
+
module Const
|
7
|
+
module PI
|
8
|
+
module_function
|
9
|
+
# Implement by Ramanujan's formula.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# BigMathR::Const::PI.ramanujan2(20)
|
13
|
+
# #=> 0.31415926535897932385e1
|
14
|
+
# @param prec [Integer] Arbitrary precision
|
15
|
+
# @return [BigDecimal] Constant PI
|
16
|
+
# @raise [TypeError] not an Integer
|
17
|
+
# @raise [RangeError] Zero or negative precision
|
18
|
+
def ramanujan2(prec)
|
19
|
+
raise TypeError, "precision must be an Integer" unless prec.class == Integer
|
20
|
+
raise RangeError, "Zero or negative precision" if prec <= 0
|
21
|
+
n = BigDecimal.double_fig + prec
|
22
|
+
|
23
|
+
i = 0
|
24
|
+
r = 1/882r
|
25
|
+
k = 1123
|
26
|
+
|
27
|
+
d = BigDecimal(1)
|
28
|
+
y = BigDecimal(0)
|
29
|
+
|
30
|
+
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
31
|
+
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
32
|
+
d = BigDecimal(r * k, m)
|
33
|
+
y = y + d
|
34
|
+
i = i.succ
|
35
|
+
k += 21460
|
36
|
+
r = -r
|
37
|
+
r *= (2 * i - 1) * (4 * i - 3) * (4 * i - 1)
|
38
|
+
r /= 777924
|
39
|
+
r /= 32
|
40
|
+
3.times { r /= i }
|
41
|
+
end
|
42
|
+
BigDecimal(4).div(y, prec)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|