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.
Files changed (309) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/CODE_OF_CONDUCT.md +132 -0
  4. data/LICENSE +21 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +41 -0
  7. data/Rakefile +13 -0
  8. data/changelog.md +24 -0
  9. data/ext/bigdecimal/math_r/algofunc.h +203 -0
  10. data/ext/bigdecimal/math_r/api/bigdecimal/check_precise.h +12 -0
  11. data/ext/bigdecimal/math_r/api/bigdecimal/infinity.h +6 -0
  12. data/ext/bigdecimal/math_r/api/bigdecimal/minus_infinity.h +5 -0
  13. data/ext/bigdecimal/math_r/api/bigdecimal/minus_one.h +6 -0
  14. data/ext/bigdecimal/math_r/api/bigdecimal/minus_zero.h +6 -0
  15. data/ext/bigdecimal/math_r/api/bigdecimal/nan.h +6 -0
  16. data/ext/bigdecimal/math_r/api/bigdecimal/one.h +6 -0
  17. data/ext/bigdecimal/math_r/api/bigdecimal/sign.h +10 -0
  18. data/ext/bigdecimal/math_r/api/bigdecimal/zero.h +6 -0
  19. data/ext/bigdecimal/math_r/api/bigmath/api_call1.h +5 -0
  20. data/ext/bigdecimal/math_r/api/bigmath/api_call2.h +6 -0
  21. data/ext/bigdecimal/math_r/api/bigmath/atan.h +7 -0
  22. data/ext/bigdecimal/math_r/api/bigmath/atan_adopt.h +42 -0
  23. data/ext/bigdecimal/math_r/api/bigmath/cabs.h +5 -0
  24. data/ext/bigdecimal/math_r/api/bigmath/carg.h +5 -0
  25. data/ext/bigdecimal/math_r/api/bigmath/cexp.h +5 -0
  26. data/ext/bigdecimal/math_r/api/bigmath/clog.h +5 -0
  27. data/ext/bigdecimal/math_r/api/bigmath/const.h +39 -0
  28. data/ext/bigdecimal/math_r/api/bigmath/const_e.h +5 -0
  29. data/ext/bigdecimal/math_r/api/bigmath/const_log10.h +5 -0
  30. data/ext/bigdecimal/math_r/api/bigmath/const_log2.h +5 -0
  31. data/ext/bigdecimal/math_r/api/bigmath/const_log_pi.h +5 -0
  32. data/ext/bigdecimal/math_r/api/bigmath/const_pi.h +5 -0
  33. data/ext/bigdecimal/math_r/api/bigmath/const_sqrt2.h +5 -0
  34. data/ext/bigdecimal/math_r/api/bigmath/const_sqrt3.h +5 -0
  35. data/ext/bigdecimal/math_r/api/bigmath/cpow.h +5 -0
  36. data/ext/bigdecimal/math_r/api/bigmath/csqrt.h +5 -0
  37. data/ext/bigdecimal/math_r/api/bigmath/degree_sparg.h +199 -0
  38. data/ext/bigdecimal/math_r/api/bigmath/escalb.h +5 -0
  39. data/ext/bigdecimal/math_r/api/bigmath/exp.h +5 -0
  40. data/ext/bigdecimal/math_r/api/bigmath/expxt.h +18 -0
  41. data/ext/bigdecimal/math_r/api/bigmath/hypot.h +10 -0
  42. data/ext/bigdecimal/math_r/api/bigmath/ipow.h +14 -0
  43. data/ext/bigdecimal/math_r/api/bigmath/l2norm.h +5 -0
  44. data/ext/bigdecimal/math_r/api/bigmath/log.h +7 -0
  45. data/ext/bigdecimal/math_r/api/bigmath/pow.h +5 -0
  46. data/ext/bigdecimal/math_r/api/bigmath/quadrant.h +5 -0
  47. data/ext/bigdecimal/math_r/api/bigmath/sincos.h +5 -0
  48. data/ext/bigdecimal/math_r/api/bigmath/sqrt.h +5 -0
  49. data/ext/bigdecimal/math_r/api/bigmath/to_rad.h +41 -0
  50. data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal.h +6 -0
  51. data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal1.h +6 -0
  52. data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal_flo.h +9 -0
  53. data/ext/bigdecimal/math_r/api/kernel/rb_ImaginaryZ.h +8 -0
  54. data/ext/bigdecimal/math_r/api/numanalysis/condition_p.h +26 -0
  55. data/ext/bigdecimal/math_r/api/numanalysis/make_n.h +9 -0
  56. data/ext/bigdecimal/math_r/api/numeric/abs.h +7 -0
  57. data/ext/bigdecimal/math_r/api/numeric/canonicalize.h +140 -0
  58. data/ext/bigdecimal/math_r/api/numeric/cmpeql.h +6 -0
  59. data/ext/bigdecimal/math_r/api/numeric/equal_p.h +6 -0
  60. data/ext/bigdecimal/math_r/api/numeric/finite_p.h +6 -0
  61. data/ext/bigdecimal/math_r/api/numeric/imag.h +6 -0
  62. data/ext/bigdecimal/math_r/api/numeric/infinite_p.h +7 -0
  63. data/ext/bigdecimal/math_r/api/numeric/nan_p.h +5 -0
  64. data/ext/bigdecimal/math_r/api/numeric/negative_p.h +6 -0
  65. data/ext/bigdecimal/math_r/api/numeric/nonzero_p.h +6 -0
  66. data/ext/bigdecimal/math_r/api/numeric/notequal_p.h +6 -0
  67. data/ext/bigdecimal/math_r/api/numeric/numeric_p.h +5 -0
  68. data/ext/bigdecimal/math_r/api/numeric/positive_p.h +6 -0
  69. data/ext/bigdecimal/math_r/api/numeric/real.h +6 -0
  70. data/ext/bigdecimal/math_r/api/numeric/real_p.h +6 -0
  71. data/ext/bigdecimal/math_r/api/numeric/round.h +56 -0
  72. data/ext/bigdecimal/math_r/api/numeric/uminus.h +6 -0
  73. data/ext/bigdecimal/math_r/api/numeric/zero_p.h +6 -0
  74. data/ext/bigdecimal/math_r/api.c +13 -0
  75. data/ext/bigdecimal/math_r/api.h +69 -0
  76. data/ext/bigdecimal/math_r/const.c +186 -0
  77. data/ext/bigdecimal/math_r/decl.h +203 -0
  78. data/ext/bigdecimal/math_r/edf.c +180 -0
  79. data/ext/bigdecimal/math_r/erf.c +80 -0
  80. data/ext/bigdecimal/math_r/euler_f.c +572 -0
  81. data/ext/bigdecimal/math_r/exp.c +72 -0
  82. data/ext/bigdecimal/math_r/extconf.rb +185 -0
  83. data/ext/bigdecimal/math_r/gamma_r.c +251 -0
  84. data/ext/bigdecimal/math_r/hyperb.c +172 -0
  85. data/ext/bigdecimal/math_r/internal/algo/bigmath/E/ser.h +22 -0
  86. data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG10/ser.h +16 -0
  87. data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG2/BBP2002.h +36 -0
  88. data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG_PI/builtin.h +7 -0
  89. data/ext/bigdecimal/math_r/internal/algo/bigmath/PI/machin.h +48 -0
  90. data/ext/bigdecimal/math_r/internal/algo/bigmath/SQRT2/builtin.h +5 -0
  91. data/ext/bigdecimal/math_r/internal/algo/bigmath/SQRT3/builtin.h +5 -0
  92. data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/branch.h +25 -0
  93. data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/edom.h +15 -0
  94. data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/logrep.h +19 -0
  95. data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/ser.h +34 -0
  96. data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/branch.h +19 -0
  97. data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/edom.h +17 -0
  98. data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/logrep.h +14 -0
  99. data/ext/bigdecimal/math_r/internal/algo/bigmath/acot/branch.h +16 -0
  100. data/ext/bigdecimal/math_r/internal/algo/bigmath/acot/logrep.h +13 -0
  101. data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/branch.h +20 -0
  102. data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/edom.h +18 -0
  103. data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/logrep.h +33 -0
  104. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/branch.h +21 -0
  105. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/edom.h +20 -0
  106. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/logrep.h +16 -0
  107. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsch/branch.h +25 -0
  108. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsch/logrep.h +25 -0
  109. data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/branch.h +22 -0
  110. data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/edom.h +16 -0
  111. data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/logrep.h +21 -0
  112. data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/branch.h +18 -0
  113. data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/edom.h +19 -0
  114. data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/logrep.h +16 -0
  115. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/branch.h +22 -0
  116. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/edom.h +20 -0
  117. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/logrep.h +15 -0
  118. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/ser.h +32 -0
  119. data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/branch.h +26 -0
  120. data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/logrep.h +24 -0
  121. data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/ser.h +48 -0
  122. data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/branch.h +16 -0
  123. data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/logrep.h +14 -0
  124. data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_euler.h +84 -0
  125. data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_usual.h +41 -0
  126. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/branch.h +24 -0
  127. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/edom.h +16 -0
  128. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/logrep.h +16 -0
  129. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/ser.h +33 -0
  130. data/ext/bigdecimal/math_r/internal/algo/bigmath/cabs/formula.h +8 -0
  131. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacos/branch.h +38 -0
  132. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacos/logrep.h +16 -0
  133. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacosh/branch.h +34 -0
  134. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacosh/logrep.h +17 -0
  135. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacot/branch.h +39 -0
  136. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacot/logrep.h +17 -0
  137. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacoth/branch.h +29 -0
  138. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacoth/logrep.h +11 -0
  139. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsc/branch.h +28 -0
  140. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsc/logrep.h +19 -0
  141. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsch/branch.h +18 -0
  142. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsch/logrep.h +11 -0
  143. data/ext/bigdecimal/math_r/internal/algo/bigmath/carg/formula.h +8 -0
  144. data/ext/bigdecimal/math_r/internal/algo/bigmath/casec/branch.h +29 -0
  145. data/ext/bigdecimal/math_r/internal/algo/bigmath/casec/logrep.h +18 -0
  146. data/ext/bigdecimal/math_r/internal/algo/bigmath/casech/branch.h +38 -0
  147. data/ext/bigdecimal/math_r/internal/algo/bigmath/casech/logrep.h +9 -0
  148. data/ext/bigdecimal/math_r/internal/algo/bigmath/casin/branch.h +35 -0
  149. data/ext/bigdecimal/math_r/internal/algo/bigmath/casin/logrep.h +14 -0
  150. data/ext/bigdecimal/math_r/internal/algo/bigmath/casinh/branch.h +59 -0
  151. data/ext/bigdecimal/math_r/internal/algo/bigmath/casinh/logrep.h +13 -0
  152. data/ext/bigdecimal/math_r/internal/algo/bigmath/catan/branch.h +46 -0
  153. data/ext/bigdecimal/math_r/internal/algo/bigmath/catan/logrep.h +17 -0
  154. data/ext/bigdecimal/math_r/internal/algo/bigmath/catanh/branch.h +26 -0
  155. data/ext/bigdecimal/math_r/internal/algo/bigmath/catanh/logrep.h +10 -0
  156. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccbrt/formula.h +11 -0
  157. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccos/branch.h +41 -0
  158. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccos/eulerf.h +11 -0
  159. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccosh/branch.h +37 -0
  160. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccosh/eulerf.h +11 -0
  161. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccot/branch.h +46 -0
  162. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccot/eulerf.h +11 -0
  163. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccoth/branch.h +43 -0
  164. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccoth/eulerf.h +11 -0
  165. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsc/branch.h +42 -0
  166. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsc/eulerf.h +11 -0
  167. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsch/branch.h +38 -0
  168. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsch/eulerf.h +11 -0
  169. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp/branch.h +42 -0
  170. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp/eulerf.h +21 -0
  171. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp2/branch.h +42 -0
  172. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp2/eulerf.h +12 -0
  173. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog/branch.h +54 -0
  174. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog/formula.h +13 -0
  175. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog10/formula.h +12 -0
  176. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog1p/branch.h +34 -0
  177. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog2/formula.h +12 -0
  178. data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/branch.h +21 -0
  179. data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/eulerf.h +11 -0
  180. data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/ser.h +12 -0
  181. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/branch.h +22 -0
  182. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/eulerf.h +11 -0
  183. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/formula.h +30 -0
  184. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/ser.h +11 -0
  185. data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/branch.h +28 -0
  186. data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/eulerf.h +11 -0
  187. data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/ser.h +12 -0
  188. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/branch.h +23 -0
  189. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/eulerf.h +11 -0
  190. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/formula.h +30 -0
  191. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/ser.h +13 -0
  192. data/ext/bigdecimal/math_r/internal/algo/bigmath/cpow/formula.h +20 -0
  193. data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/branch.h +28 -0
  194. data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/eulerf.h +11 -0
  195. data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/ser.h +11 -0
  196. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/branch.h +23 -0
  197. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/eulerf.h +11 -0
  198. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/formula.h +31 -0
  199. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/ser.h +11 -0
  200. data/ext/bigdecimal/math_r/internal/algo/bigmath/csec/branch.h +42 -0
  201. data/ext/bigdecimal/math_r/internal/algo/bigmath/csec/eulerf.h +11 -0
  202. data/ext/bigdecimal/math_r/internal/algo/bigmath/csech/branch.h +38 -0
  203. data/ext/bigdecimal/math_r/internal/algo/bigmath/csech/eulerf.h +11 -0
  204. data/ext/bigdecimal/math_r/internal/algo/bigmath/csin/branch.h +44 -0
  205. data/ext/bigdecimal/math_r/internal/algo/bigmath/csin/eulerf.h +11 -0
  206. data/ext/bigdecimal/math_r/internal/algo/bigmath/csinh/branch.h +41 -0
  207. data/ext/bigdecimal/math_r/internal/algo/bigmath/csinh/eulerf.h +11 -0
  208. data/ext/bigdecimal/math_r/internal/algo/bigmath/csqrt/formula.h +66 -0
  209. data/ext/bigdecimal/math_r/internal/algo/bigmath/ctan/branch.h +46 -0
  210. data/ext/bigdecimal/math_r/internal/algo/bigmath/ctan/eulerf.h +11 -0
  211. data/ext/bigdecimal/math_r/internal/algo/bigmath/ctanh/branch.h +43 -0
  212. data/ext/bigdecimal/math_r/internal/algo/bigmath/ctanh/eulerf.h +11 -0
  213. data/ext/bigdecimal/math_r/internal/algo/bigmath/cuberoot/newton.h +42 -0
  214. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/algo911.h +41 -0
  215. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/branch.h +18 -0
  216. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/cf.h +51 -0
  217. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/ser_inf.h +53 -0
  218. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/ser_zero.h +45 -0
  219. data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/algo911.h +27 -0
  220. data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/branch.h +18 -0
  221. data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/cf.h +49 -0
  222. data/ext/bigdecimal/math_r/internal/algo/bigmath/escalb/edf.h +87 -0
  223. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/branch.h +29 -0
  224. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/builtin.h +6 -0
  225. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/edf.h +23 -0
  226. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp2/branch.h +29 -0
  227. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp2/edf.h +19 -0
  228. data/ext/bigdecimal/math_r/internal/algo/bigmath/expxt/edf.h +31 -0
  229. data/ext/bigdecimal/math_r/internal/algo/bigmath/f_euler/formula.h +11 -0
  230. data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/branch.h +25 -0
  231. data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/l2norm.h +11 -0
  232. data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/mmm.h +38 -0
  233. data/ext/bigdecimal/math_r/internal/algo/bigmath/ipow/edf.h +33 -0
  234. data/ext/bigdecimal/math_r/internal/algo/bigmath/l2norm/formula.h +48 -0
  235. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/branch.h +40 -0
  236. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/builtin.h +12 -0
  237. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/edf.h +10 -0
  238. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/edom.h +10 -0
  239. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/mercator.h +34 -0
  240. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/ser_okumura.h +57 -0
  241. data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/branch.h +40 -0
  242. data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/edf.h +11 -0
  243. data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/mercator.h +35 -0
  244. data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/branch.h +34 -0
  245. data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/p_adic.h +37 -0
  246. data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/ser_mercator.h +35 -0
  247. data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/branch.h +40 -0
  248. data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/edf.h +11 -0
  249. data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/mercator.h +35 -0
  250. data/ext/bigdecimal/math_r/internal/algo/bigmath/logxt/edf.h +33 -0
  251. data/ext/bigdecimal/math_r/internal/algo/bigmath/pow/formula.h +30 -0
  252. data/ext/bigdecimal/math_r/internal/algo/bigmath/quadrant/formula.h +352 -0
  253. data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm10/edf.h +34 -0
  254. data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm2/edf.h +34 -0
  255. data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/branch.h +27 -0
  256. data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/eulerf.h +11 -0
  257. data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/ser.h +11 -0
  258. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/branch.h +21 -0
  259. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/eulerf.h +11 -0
  260. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/formula.h +25 -0
  261. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/ser.h +11 -0
  262. data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/branch.h +23 -0
  263. data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/eulerf.h +11 -0
  264. data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/ser.h +13 -0
  265. data/ext/bigdecimal/math_r/internal/algo/bigmath/sincos/ser.h +50 -0
  266. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/branch.h +23 -0
  267. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/eulerf.h +11 -0
  268. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/formula.h +26 -0
  269. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/ser.h +11 -0
  270. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinhcosh/ser.h +70 -0
  271. data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/branch.h +16 -0
  272. data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/builtin.h +12 -0
  273. data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/edom.h +9 -0
  274. data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/newton.h +36 -0
  275. data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/branch.h +26 -0
  276. data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/eulerf.h +11 -0
  277. data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/ser.h +18 -0
  278. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/branch.h +23 -0
  279. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/eulerf.h +11 -0
  280. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/formula.h +27 -0
  281. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/ser.h +14 -0
  282. data/ext/bigdecimal/math_r/internal/algo/bigmath/trig/f_euler.h +290 -0
  283. data/ext/bigdecimal/math_r/log.c +256 -0
  284. data/ext/bigdecimal/math_r/logrep.c +537 -0
  285. data/ext/bigdecimal/math_r/math_r/bigdecimal.h +30 -0
  286. data/ext/bigdecimal/math_r/math_r/bigmath.h +61 -0
  287. data/ext/bigdecimal/math_r/math_r/bigmath_r.h +9 -0
  288. data/ext/bigdecimal/math_r/math_r/ext_extern.h +18 -0
  289. data/ext/bigdecimal/math_r/math_r/globals.h +71 -0
  290. data/ext/bigdecimal/math_r/math_r/numdiff.h +18 -0
  291. data/ext/bigdecimal/math_r/math_r/numeric.h +63 -0
  292. data/ext/bigdecimal/math_r/math_r.c +130 -0
  293. data/ext/bigdecimal/math_r/nucomp.c +158 -0
  294. data/ext/bigdecimal/math_r/overrides.c +91 -0
  295. data/ext/bigdecimal/math_r/power.c +207 -0
  296. data/ext/bigdecimal/math_r/solver.c +1516 -0
  297. data/ext/bigdecimal/math_r/trig.c +205 -0
  298. data/lib/bigdecimal/math_r/const/EulerGamma_engel.rb +46 -0
  299. data/lib/bigdecimal/math_r/const/LOG2_bbp2007.rb +39 -0
  300. data/lib/bigdecimal/math_r/const/PI_chudnovsky.rb +59 -0
  301. data/lib/bigdecimal/math_r/const/PI_euler.rb +40 -0
  302. data/lib/bigdecimal/math_r/const/PI_ramanujan1.rb +45 -0
  303. data/lib/bigdecimal/math_r/const/PI_ramanujan2.rb +46 -0
  304. data/lib/bigdecimal/math_r/const/b053977/b053977.txt +306 -0
  305. data/lib/bigdecimal/math_r/version.rb +7 -0
  306. data/lib/bigdecimal/math_r.rb +12 -0
  307. data/lib/bigdecimal/math_r.so +0 -0
  308. data/sig/bigdecimal/math_r.rbs +6 -0
  309. metadata +393 -0
@@ -0,0 +1,39 @@
1
+ static VALUE
2
+ init_prec(VALUE prec)
3
+ {
4
+ const ID double_fig = rb_intern("double_fig");
5
+ VALUE fig, retval = Qnil;
6
+
7
+ rb_check_precise(prec);
8
+
9
+ fig = rb_funcall(rb_cBigDecimal, double_fig, 0);
10
+
11
+ switch (NUM2INT(rb_dbl_cmp(NUM2DBL(prec), NUM2DBL(fig)))) {
12
+ case -1:
13
+ retval = fig;
14
+ break;
15
+ case 0:
16
+ case 1:
17
+ retval = prec;
18
+ }
19
+
20
+ return retval;
21
+ }
22
+
23
+ VALUE
24
+ rb_bigmath_const(const char *gv, VALUE (*func)(VALUE prec), VALUE prec)
25
+ {
26
+ static long def_prec = DEF_PREC;
27
+ VALUE x;
28
+
29
+ x = rb_gv_get(gv);
30
+ prec = init_prec(prec);
31
+ if (def_prec < NUM2LONG(prec) || NIL_P(x))
32
+ {
33
+ if (def_prec < NUM2LONG(prec))
34
+ def_prec = NUM2LONG(prec);
35
+ x = func(LONG2FIX(def_prec));
36
+ rb_gv_set(gv, x);
37
+ }
38
+ return rb_num_round(x, prec);
39
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_e(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_E, E_ser, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_log10(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_LOG10, LOG10_ser, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_log2(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_LOG2, LOG2_BBP2002, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_log_pi(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_LOG_PI, LOG_PI_builtin, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_pi(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_PI, PI_machin, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_sqrt2(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_SQRT2, SQRT2_builtin, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_const_sqrt3(VALUE prec)
3
+ {
4
+ return rb_bigmath_const(BIGMATH_SQRT3, SQRT3_builtin, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_cpow(VALUE z, VALUE w, VALUE prec)
3
+ {
4
+ return cpow_formula(z, w, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_csqrt(VALUE z, VALUE prec)
3
+ {
4
+ return csqrt_formula(z, prec);
5
+ }
@@ -0,0 +1,199 @@
1
+
2
+
3
+ /**
4
+ * Degree | Rational | $P(x, y) = (\cos\theta, \sin\theta)$
5
+ * 360-deg | 0/1 | $(1, 0)$
6
+ * 30-deg | 1/6 | $(\frac{\sqrt{3}}{2}, \frac{1}{2})$
7
+ * 45-deg | 1/4 | $(\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$
8
+ * 60-deg | 1/3 | $(\frac{1}{2}, \frac{\sqrt{3}}{2})$
9
+ * 90-deg | 1/2 | $(0, 1)$
10
+ * 120-deg | 2/3 | $(-\frac{1}{2}, \frac{\sqrt{3}}{2})$
11
+ * 135-deg | 3/4 | $(-\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$
12
+ * 150-deg | 5/6 | $(-\frac{\sqrt{3}}{2}, \frac{1}{2})$
13
+ * 180-deg | 1/1 | $(-1, 0)$
14
+ * 210-deg | 7/6 | $(-\frac{\sqrt{3}}{2}, -\frac{1}{2})$
15
+ * 225-deg | 5/4 | $(-\frac{\sqrt{2}}{2}, -\frac{\sqrt{2}}{2})$
16
+ * 240-deg | 4/3 | $(-\frac{1}{2}, -\frac{\sqrt{3}}{2})$
17
+ * 270-deg | 3/2 | $(0, -1)$
18
+ * 300-deg | 5/3 | $(\frac{1}{2}, -\frac{\sqrt{3}}{2})$
19
+ * 315-deg | 7/4 | $(\frac{\sqrt{2}}{2}, -\frac{\sqrt{2}}{2})$
20
+ * 330-deg | 11/6 | $(\frac{\sqrt{3}}{2}, -\frac{1}{2})$
21
+ *
22
+ * ```Ruby
23
+ * def sparg_list(prec)
24
+ * funcs = [:sin, :cos, :tan, :csc, :sec, :cot]
25
+ * degrees = [
26
+ * 0/1r, 1/6r, 1/4r, 1/3r, 1/2r, 2/3r, 3/4r, 5/6r,
27
+ * 1r, 7/6r, 5/4r, 4/3r, 3/2r, 5/3r, 7/4r, 11/6r
28
+ * ]
29
+ * degree_num = [
30
+ * 360, 30, 45, 60, 90, 120, 135, 150,
31
+ * 180, 210, 225, 240, 270, 300, 315, 330
32
+ * ]
33
+ * pi = BigMath.PI(prec)
34
+ *
35
+ * puts (["Degree"] + funcs).map{|func| (" " + func.to_s).ljust(prec+5, " ")}.join(" ")
36
+ *
37
+ * degree_num.zip(degrees).each do |deg, rat|
38
+ * list = [deg]
39
+ * funcs.each do |func|
40
+ * meth = BigMathR::Trigonometric.method(func)
41
+ * y = meth.call(rat * pi, prec)
42
+ * list << y
43
+ * end
44
+ * puts list.map{|x| ((x = x.to_s)[0] == '-' ? x : " " + x.to_s).ljust(prec+5, " ")}.join(" ")
45
+ * end
46
+ * end
47
+ * ```
48
+ *
49
+ * ```
50
+ * $ sparg_list(8)
51
+ * Degree sin cos tan csc sec cot
52
+ * 360 0.0 0.1e1 0.0 Infinity 0.1e1 Infinity
53
+ * 30 0.5e0 0.8660254e0 0.57735027e0 0.2e1 0.11547005e1 0.17320508e1
54
+ * 45 0.70710678e0 0.70710678e0 0.1e1 0.14142136e1 0.14142136e1 0.1e1
55
+ * 60 0.8660254e0 0.5e0 0.17320508e1 0.11547005e1 0.2e1 0.57735027e0
56
+ * 90 0.1e1 0.0 Infinity 0.1e1 Infinity 0.0
57
+ * 120 0.8660254e0 -0.5e0 -0.17320508e1 0.11547005e1 -0.2e1 -0.57735027e0
58
+ * 135 0.70710678e0 -0.70710678e0 -0.1e1 0.14142136e1 -0.14142136e1 -0.1e1
59
+ * 150 0.5e0 -0.8660254e0 -0.57735027e0 0.2e1 -0.11547005e1 -0.17320508e1
60
+ * 180 0.0 -0.1e1 -0.0 Infinity -0.1e1 -Infinity
61
+ * 210 -0.5e0 -0.8660254e0 0.57735027e0 -0.2e1 -0.11547005e1 0.17320508e1
62
+ * 225 -0.70710678e0 -0.70710678e0 0.1e1 -0.14142136e1 -0.14142136e1 0.1e1
63
+ * 240 -0.8660254e0 -0.5e0 0.17320508e1 -0.11547005e1 -0.2e1 0.57735027e0
64
+ * 270 -0.1e1 0.0 -Infinity -0.1e1 Infinity -0.0
65
+ * 300 -0.8660254e0 0.5e0 -0.17320508e1 -0.11547005e1 0.2e1 -0.57735027e0
66
+ * 315 -0.70710678e0 0.70710678e0 -0.1e1 -0.14142136e1 0.14142136e1 -0.1e1
67
+ * 330 -0.5e0 0.8660254e0 -0.57735027e0 -0.2e1 0.11547005e1 -0.17320508e1
68
+ * ```
69
+ * --------------------------------- SYNOPSIS ---------------------------------
70
+ */
71
+
72
+ int
73
+ rb_bigmath_degree_sparg(VALUE t, VALUE prec, VALUE *sin, VALUE *cos)
74
+ {
75
+ const ID div = rb_intern("div");
76
+ #define angle_equal_p(d) \
77
+ rb_num_equal_p(t, INT2FIX(d))
78
+ #define HALF \
79
+ rb_funcall(BIG_ONE, div, 2, INT2FIX(2), prec)
80
+ #define HALF_M \
81
+ rb_funcall(BIG_ONE, div, 2, INT2FIX(-2), prec)
82
+ #define SQRT2_2 \
83
+ rb_funcall(rb_bigmath_const_sqrt2(prec), div, 2, INT2FIX(2), prec)
84
+ #define SQRT2_2_M \
85
+ rb_funcall(rb_bigmath_const_sqrt2(prec), div, 2, INT2FIX(-2), prec)
86
+ #define SQRT3_2 \
87
+ rb_funcall(rb_bigmath_const_sqrt3(prec), div, 2, INT2FIX(2), prec)
88
+ #define SQRT3_2_M \
89
+ rb_funcall(rb_bigmath_const_sqrt3(prec), div, 2, INT2FIX(-2), prec)
90
+
91
+ if (angle_equal_p(0))
92
+ {
93
+ if (cos != NULL) *cos = BIG_ONE;
94
+ if (sin != NULL) *sin = BIG_ZERO;
95
+ return 1;
96
+ }
97
+ else if (angle_equal_p(30))
98
+ {
99
+ if (cos != NULL) *cos = SQRT3_2;
100
+ if (sin != NULL) *sin = HALF;
101
+ return 1;
102
+ }
103
+ else if (angle_equal_p(45))
104
+ {
105
+ if (cos != NULL) *cos = SQRT2_2;
106
+ if (sin != NULL) *sin = SQRT2_2;
107
+ return 1;
108
+ }
109
+ else if (angle_equal_p(60))
110
+ {
111
+ if (cos != NULL) *cos = HALF;
112
+ if (sin != NULL) *sin = SQRT3_2;
113
+
114
+ return 1;
115
+ }
116
+ else if (angle_equal_p(90))
117
+ {
118
+ if (cos != NULL) *cos = BIG_ZERO;
119
+ if (sin != NULL) *sin = BIG_ONE;
120
+ return 1;
121
+ }
122
+ else if (angle_equal_p(120))
123
+ {
124
+ if (cos != NULL) *cos = HALF_M;
125
+ if (sin != NULL) *sin = SQRT3_2;
126
+ return 1;
127
+ }
128
+ else if (angle_equal_p(135))
129
+ {
130
+ if (cos != NULL) *cos = SQRT2_2_M;
131
+ if (sin != NULL) *sin = SQRT2_2;
132
+ return 1;
133
+ }
134
+ else if (angle_equal_p(150))
135
+ {
136
+ if (cos != NULL) *cos = SQRT3_2_M;
137
+ if (sin != NULL) *sin = HALF;
138
+ return 1;
139
+ }
140
+ else if (angle_equal_p(180))
141
+ {
142
+ if (cos != NULL) *cos = BIG_MINUS_ONE;
143
+ if (sin != NULL) *sin = BIG_ZERO;
144
+ return 1;
145
+ }
146
+ else if (angle_equal_p(210))
147
+ {
148
+ if (cos != NULL) *cos = SQRT3_2_M;
149
+ if (sin != NULL) *sin = HALF_M;
150
+ return 1;
151
+ }
152
+ else if (angle_equal_p(225))
153
+ {
154
+ if (cos != NULL) *cos = SQRT2_2_M;
155
+ if (sin != NULL) *sin = SQRT2_2_M;
156
+ return 1;
157
+ }
158
+ else if (angle_equal_p(240))
159
+ {
160
+ if (cos != NULL) *cos = HALF_M;
161
+ if (sin != NULL) *sin = SQRT3_2_M;
162
+ return 1;
163
+ }
164
+ else if (angle_equal_p(270))
165
+ {
166
+ if (cos != NULL) *cos = BIG_ZERO;
167
+ if (sin != NULL) *sin = BIG_MINUS_ONE;
168
+ return 1;
169
+ }
170
+ else if (angle_equal_p(300))
171
+ {
172
+ if (cos != NULL) *cos = HALF;
173
+ if (sin != NULL) *sin = SQRT3_2_M;
174
+ return 1;
175
+ }
176
+ else if (angle_equal_p(315))
177
+ {
178
+ if (cos != NULL) *cos = SQRT2_2;
179
+ if (sin != NULL) *sin = SQRT2_2_M;
180
+ return 1;
181
+ }
182
+ else if (angle_equal_p(330))
183
+ {
184
+ if (cos != NULL) *cos = SQRT3_2;
185
+ if (sin != NULL) *sin = HALF_M;
186
+ return 1;
187
+ }
188
+ #undef angle_equal_p
189
+ #undef HALF
190
+ #undef HALF_M
191
+ #undef SQRT2_2
192
+ #undef SQRT2_2_M
193
+ #undef SQRT3_2
194
+ #undef SQRT3_2_M
195
+ else
196
+ {
197
+ return -1;
198
+ }
199
+ }
@@ -0,0 +1,5 @@
1
+ void
2
+ rb_bigmath_escalb(VALUE a, VALUE x, VALUE prec, VALUE *exp, VALUE *fra)
3
+ {
4
+ return escalb_edf(a, x, prec, exp, fra);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_exp(VALUE x, VALUE prec)
3
+ {
4
+ return exp_edf(x, prec);
5
+ }
@@ -0,0 +1,18 @@
1
+ VALUE
2
+ rb_bigmath_expxt(VALUE x, VALUE t, VALUE prec)
3
+ {
4
+ rb_check_precise(prec);
5
+ x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
6
+ if (rb_num_notequal_p(x, x) ||
7
+ rb_num_negative_p(x) ||
8
+ NUM2INT(rb_num_cmpeql(x, INT2FIX(1))) == 1)
9
+ rb_raise(rb_eRangeError, "Argument x is out of range: (0 <= x <= 1)");
10
+ t = rb_num_canonicalize(t, prec, ARG_REAL, ARG_RAWVALUE);
11
+ if (rb_num_notequal_p(t, t) ||
12
+ rb_num_negative_p(t) ||
13
+ NUM2INT(rb_num_cmpeql(t, INT2FIX(1))) == 1)
14
+ rb_raise(rb_eRangeError, "Argument t is out of range: (0 <= t <= 1)");
15
+ if (!rb_num_finite_p(x) || !rb_num_finite_p(t))
16
+ rb_raise(rb_eFloatDomainError, "not a finite");
17
+ return expxt_edf(x, t, prec);
18
+ }
@@ -0,0 +1,10 @@
1
+ VALUE
2
+ rb_bigmath_hypot(VALUE a, VALUE b, VALUE prec)
3
+ {
4
+ if (rb_num_zero_p(rb_num_imag(a)) &&
5
+ rb_num_zero_p(rb_num_imag(b)))
6
+ return hypot_branch(a, b, prec, hypot_mmm);
7
+ else
8
+ return hypot_branch(a, b, prec, hypot_l2norm);
9
+ }
10
+
@@ -0,0 +1,14 @@
1
+ VALUE
2
+ rb_bigmath_ipow(VALUE x, VALUE n, VALUE exp)
3
+ {
4
+ VALUE y;
5
+
6
+ rb_check_precise(exp);
7
+ x = rb_num_canonicalize(x, exp, ARG_REAL, ARG_RAWVALUE);
8
+ if (!(TYPE(n) == T_FIXNUM || TYPE(n) == T_BIGNUM))
9
+ rb_raise(rb_eTypeError, "right-hand side must be an Integer");
10
+
11
+ y = ipow_edf(x, n, exp);
12
+
13
+ return y;
14
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_l2norm(VALUE vec, VALUE prec)
3
+ {
4
+ return l2norm_formula(vec, prec);
5
+ }
@@ -0,0 +1,7 @@
1
+
2
+
3
+ VALUE
4
+ rb_bigmath_log(VALUE x, VALUE prec)
5
+ {
6
+ return log_branch(x, prec, log_builtin);
7
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_pow(VALUE z, VALUE w, VALUE prec)
3
+ {
4
+ return pow_formula(z, w, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_quadrant(VALUE x, VALUE y, VALUE prec)
3
+ {
4
+ return quadrant_formula(x, y, prec);
5
+ }
@@ -0,0 +1,5 @@
1
+ void
2
+ rb_bigmath_sincos(VALUE x, VALUE prec, VALUE *sin, VALUE *cos)
3
+ {
4
+ sincos_ser(x, prec, sin, cos);
5
+ }
@@ -0,0 +1,5 @@
1
+ VALUE
2
+ rb_bigmath_sqrt(VALUE x, VALUE prec)
3
+ {
4
+ return sqrt_branch(x, prec, sqrt_newton);
5
+ }
@@ -0,0 +1,41 @@
1
+ VALUE
2
+ rb_bigmath_to_rad(VALUE x, VALUE prec, VALUE *t)
3
+ {
4
+ const ID mult = rb_intern("mult");
5
+ VALUE n = rb_numdiff_make_n(prec);
6
+ VALUE twopi = rb_bigmath_const_pi(n); twopi = rb_funcall1(twopi, '*', INT2FIX(2));
7
+ bool neg = false;
8
+ if (NUM2INT(rb_num_cmpeql(x, rb_num_uminus(twopi))) == -1 ||
9
+ NUM2INT(rb_num_cmpeql(twopi, x)) == -1)
10
+ {
11
+ neg = rb_num_negative_p(x);
12
+ if (neg)
13
+ x = rb_num_uminus(x);
14
+ if (rb_num_cmpeql(x, INT2FIX(30)) == 1)
15
+ x = rb_funcall1(x, '%', twopi);
16
+ else
17
+ while (RTEST(rb_num_coerce_cmp(x, twopi, '>')))
18
+ x = rb_funcall1(x, '-', twopi);
19
+ if (neg)
20
+ x = rb_num_uminus(x);
21
+ }
22
+ else
23
+ {
24
+ x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
25
+ }
26
+ if (t != NULL)
27
+ {
28
+ *t = rb_num_round(
29
+ rb_funcall1(x, '/', twopi), prec);
30
+ if (rb_num_negative_p(*t))
31
+ rb_funcall1(x, '+', INT2FIX(1));
32
+ *t = rb_funcall(*t, mult, 2, INT2FIX(360), prec);
33
+ }
34
+ #if 0
35
+ if (NUM2INT(rb_num_cmpeql(x, rb_num_uminus(pi))) == -1)
36
+ x = rb_funcall1(x, '+', twopi);
37
+ else if (NUM2INT(rb_num_cmpeql(pi, x)) == -1)
38
+ x = rb_funcall1(x, '-', twopi);
39
+ #endif
40
+ return x;
41
+ }
@@ -0,0 +1,6 @@
1
+ VALUE
2
+ rb_BigDecimal(VALUE x, VALUE prec)
3
+ {
4
+ const ID BigDecimal = rb_intern("BigDecimal");
5
+ return rb_funcall(rb_cObject, BigDecimal, 2, x, prec);
6
+ }
@@ -0,0 +1,6 @@
1
+ VALUE
2
+ rb_BigDecimal1(VALUE x)
3
+ {
4
+ const ID BigDecimal = rb_intern("BigDecimal");
5
+ return rb_funcall(rb_cObject, BigDecimal, 1, x);
6
+ }
@@ -0,0 +1,9 @@
1
+ VALUE
2
+ rb_BigDecimal_flo(VALUE x)
3
+ {
4
+ const ID BigDecimal = rb_intern("BigDecimal");
5
+ const ID DIG = rb_intern("DIG");
6
+ VALUE FLOAT_DIG = rb_const_get_at(rb_cFloat, DIG);
7
+ VALUE y = rb_funcall(rb_cObject, BigDecimal, 2, x, FLOAT_DIG);
8
+ return y;
9
+ }
@@ -0,0 +1,8 @@
1
+ VALUE
2
+ rb_ImaginaryZ(VALUE z, bool signbit)
3
+ {
4
+ VALUE real, imag;
5
+ real = signbit ? rb_num_imag(z) : rb_num_uminus(rb_num_imag(z));
6
+ imag = signbit ? rb_num_uminus(rb_num_real(z)) : rb_num_real(z);
7
+ return rb_Complex(real, imag);
8
+ }
@@ -0,0 +1,26 @@
1
+ static inline void
2
+ rb_numdiff_keep_fig(VALUE *m)
3
+ {
4
+ const ID double_fig = rb_intern("double_fig");
5
+ VALUE dbl_fig = rb_funcall(rb_cBigDecimal, double_fig, 0);
6
+ if (RTEST(rb_num_coerce_cmp(*m, dbl_fig, '<')))
7
+ *m = dbl_fig;
8
+ }
9
+
10
+ bool
11
+ rb_numdiff_condition_p(VALUE y, VALUE d, VALUE n, VALUE *m)
12
+ {
13
+ const ID exponent = rb_intern("exponent");
14
+ const ID abs = rb_intern("abs");
15
+ *m = rb_funcall(n, '-', 1,
16
+ rb_funcall(
17
+ rb_funcall(
18
+ rb_funcall(y, exponent, 0), '-', 1,
19
+ rb_funcall(d, exponent, 0)
20
+ ), abs, 0
21
+ )
22
+ );
23
+ if (rb_num_positive_p(*m))
24
+ rb_numdiff_keep_fig(m);
25
+ return rb_num_nonzero_p(d) && rb_num_positive_p(*m);
26
+ }
@@ -0,0 +1,9 @@
1
+ VALUE
2
+ rb_numdiff_make_n(VALUE prec)
3
+ {
4
+ const ID double_fig = rb_intern("double_fig");
5
+ VALUE n;
6
+ rb_check_precise(prec);
7
+ n = rb_funcall(rb_funcall(rb_cBigDecimal, double_fig, 0), '+', 1, prec);
8
+ return n;
9
+ }
@@ -0,0 +1,7 @@
1
+ VALUE
2
+ rb_num_abs(VALUE x)
3
+ {
4
+ const ID _abs = rb_intern("abs");
5
+ x = rb_funcall(x, _abs, 0);
6
+ return x;
7
+ }
@@ -0,0 +1,140 @@
1
+ static VALUE
2
+ canonicalize_decimalize(VALUE x, VALUE prec)
3
+ {
4
+ switch (TYPE(x)) {
5
+ case T_FIXNUM:
6
+ case T_BIGNUM:
7
+ x = rb_BigDecimal1(x);
8
+ break;
9
+ case T_FLOAT:
10
+ x = rb_BigDecimal_flo(x);
11
+ break;
12
+ case T_RATIONAL:
13
+ x = rb_BigDecimal(x, prec);
14
+ break;
15
+ default:
16
+ break;
17
+ }
18
+ return x;
19
+ }
20
+
21
+ static inline VALUE
22
+ canonicalize_iter(RB_BLOCK_CALL_FUNC_ARGLIST(val, _))
23
+ {
24
+ const ID abs2 = rb_intern("abs2");
25
+ return rb_funcall(val, abs2, 0);
26
+ }
27
+
28
+ VALUE
29
+ rb_num_canonicalize(VALUE x, VALUE prec, bool complex_form, bool inversion)
30
+ {
31
+ const ID sum = rb_intern("sum");
32
+ const ID div = rb_intern("div");
33
+ retry:
34
+ switch (TYPE(x)) {
35
+ case T_FIXNUM:
36
+ case T_BIGNUM:
37
+ if (inversion)
38
+ {
39
+ if (rb_num_zero_p(x))
40
+ x = BIG_INF;
41
+ else
42
+ {
43
+ x = rb_Rational(INT2FIX(1), x);
44
+ x = rb_BigDecimal(x, prec);
45
+ }
46
+ }
47
+ else
48
+ x = rb_BigDecimal1(x);
49
+ if (complex_form)
50
+ x = rb_Complex(x, BIG_ZERO);
51
+ break;
52
+ case T_FLOAT:
53
+ if (inversion)
54
+ x = DBL2NUM(1 / NUM2DBL(x));
55
+ x = rb_BigDecimal_flo(x);
56
+ if (complex_form)
57
+ x = rb_Complex(x, BIG_ZERO);
58
+ break;
59
+ case T_RATIONAL:
60
+ if (inversion)
61
+ x = rb_funcall1(INT2FIX(1), '/', x);
62
+ x = rb_BigDecimal(x, prec);
63
+ if (complex_form)
64
+ x = rb_Complex(x, BIG_ZERO);
65
+ break;
66
+ case T_COMPLEX:
67
+ if (rb_num_zero_p(rb_num_imag(x)))
68
+ {
69
+ x = rb_num_real(x);
70
+ goto retry;
71
+ }
72
+ else if (!complex_form && rb_num_nonzero_p(rb_num_imag(x)))
73
+ rb_raise(rb_eTypeError, "not a Real");
74
+ else if (
75
+ (!complex_form &&
76
+ rb_num_zero_p(rb_num_imag(x))) ||
77
+ (complex_form &&
78
+ rb_num_infinite_p(rb_num_real(x)) &&
79
+ rb_num_finite_p(rb_num_imag(x))))
80
+ {
81
+ x = rb_num_real(x);
82
+ goto retry;
83
+ }
84
+ else if (complex_form && inversion && rb_num_infinite_p(rb_num_imag(x)))
85
+ {
86
+ if (rb_num_finite_p(rb_num_real(x)))
87
+ x = rb_Complex(BIG_ZERO, BIG_ZERO);
88
+ else
89
+ x = rb_Complex(BIG_NAN, BIG_NAN);
90
+ }
91
+ else if (complex_form)
92
+ {
93
+ VALUE norm, real, imag, n = rb_numdiff_make_n(prec);
94
+ ;
95
+ real = canonicalize_decimalize(rb_num_real(x), n);
96
+ imag = canonicalize_decimalize(rb_num_imag(x), n);
97
+ if (inversion)
98
+ {
99
+ norm = rb_block_call(
100
+ rb_assoc_new(
101
+ rb_num_real(x),
102
+ rb_num_imag(x)),
103
+ sum, 0, NULL,
104
+ canonicalize_iter, n);
105
+ real = rb_funcall(real, div, 2, norm, prec);
106
+ imag = rb_funcall(imag, div, 2, norm, prec);
107
+ x = rb_Complex(real, rb_num_uminus(imag));
108
+ }
109
+ else
110
+ {
111
+ x = rb_Complex(real, imag);
112
+ }
113
+ }
114
+ else
115
+ x = rb_Complex(BIG_NAN, BIG_NAN);
116
+ break;
117
+ case T_NIL: case T_TRUE: case T_FALSE:
118
+ rb_raise(rb_eTypeError,
119
+ "can't convert %"PRIsVALUE" into Numeric", rb_inspect(x));
120
+ break;
121
+ default:
122
+ if (rb_class_superclass(CLASS_OF(x)) != rb_cNumeric)
123
+ rb_raise(rb_eTypeError,
124
+ "can't convert %"PRIsVALUE" into Numeric", CLASS_OF(x));
125
+ else if (CLASS_OF(x) == rb_cBigDecimal)
126
+ {
127
+ if (inversion)
128
+ {
129
+ x = rb_funcall(BIG_ONE, div, 2, x, prec);
130
+ x = rb_num_round(x, prec);
131
+ }
132
+ if (complex_form)
133
+ x = rb_Complex(x, BIG_ZERO);
134
+ }
135
+ break;
136
+ }
137
+ if (complex_form && rb_num_real_p(x))
138
+ x = rb_Complex(x, BIG_ZERO);
139
+ return x;
140
+ }
@@ -0,0 +1,6 @@
1
+ VALUE
2
+ rb_num_cmpeql(VALUE lhs, VALUE rhs)
3
+ {
4
+ const ID cmpeql = rb_intern("<=>");
5
+ return rb_num_coerce_cmp(lhs, rhs, cmpeql);
6
+ }
@@ -0,0 +1,6 @@
1
+ bool
2
+ rb_num_equal_p(VALUE lhs, VALUE rhs)
3
+ {
4
+ const ID equal = rb_intern("==");
5
+ return RTEST(rb_num_coerce_cmp(lhs, rhs, equal));
6
+ }