bigdecimal-math_r 0.2.1 → 0.2.2

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 (164) hide show
  1. checksums.yaml +4 -4
  2. data/changelog.md +14 -0
  3. data/ext/bigdecimal/math_r/algofunc.h +11 -1
  4. data/ext/bigdecimal/math_r/api/bigmath/const_e.h +1 -1
  5. data/ext/bigdecimal/math_r/api/bigmath/const_euler_gamma.h +5 -0
  6. data/ext/bigdecimal/math_r/api/bigmath/csqrt.h +1 -1
  7. data/ext/bigdecimal/math_r/api/kernel/rb_BigDecimal_flo.h +8 -2
  8. data/ext/bigdecimal/math_r/api/numeric/nan_p.h +4 -1
  9. data/ext/bigdecimal/math_r/api.h +2 -0
  10. data/ext/bigdecimal/math_r/const.c +42 -5
  11. data/ext/bigdecimal/math_r/decl.h +11 -1
  12. data/ext/bigdecimal/math_r/exp.c +45 -3
  13. data/ext/bigdecimal/math_r/extconf.rb +5 -1
  14. data/ext/bigdecimal/math_r/{gamma_r.c → gamma_beta.c} +11 -78
  15. data/ext/bigdecimal/math_r/internal/algo/bigmath/E/{ser.h → napier.h} +1 -1
  16. data/ext/bigdecimal/math_r/internal/algo/bigmath/EulerGamma/borwein_bailey.h +37 -0
  17. data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG10/ser.h +4 -2
  18. data/ext/bigdecimal/math_r/internal/algo/bigmath/LOG_PI/builtin.h +3 -1
  19. data/ext/bigdecimal/math_r/internal/algo/bigmath/SQRT2/builtin.h +4 -1
  20. data/ext/bigdecimal/math_r/internal/algo/bigmath/SQRT3/builtin.h +4 -1
  21. data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/edom.h +7 -5
  22. data/ext/bigdecimal/math_r/internal/algo/bigmath/acot/logrep.h +9 -6
  23. data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/edom.h +4 -3
  24. data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/logrep.h +5 -2
  25. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/edom.h +7 -6
  26. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/logrep.h +6 -5
  27. data/ext/bigdecimal/math_r/internal/algo/bigmath/acsch/logrep.h +7 -6
  28. data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/edom.h +7 -6
  29. data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/logrep.h +8 -7
  30. data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/edom.h +10 -6
  31. data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/logrep.h +3 -2
  32. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/edom.h +6 -5
  33. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/logrep.h +3 -2
  34. data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/ser.h +1 -0
  35. data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/logrep.h +6 -5
  36. data/ext/bigdecimal/math_r/internal/algo/bigmath/asinh/ser.h +1 -0
  37. data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/logrep.h +7 -6
  38. data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_euler.h +2 -0
  39. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/edom.h +6 -3
  40. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/logrep.h +2 -0
  41. data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/ser.h +1 -0
  42. data/ext/bigdecimal/math_r/internal/algo/bigmath/cabs/formula.h +6 -2
  43. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacos/logrep.h +7 -4
  44. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacosh/logrep.h +6 -5
  45. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacot/logrep.h +3 -2
  46. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacoth/logrep.h +8 -4
  47. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsc/logrep.h +5 -4
  48. data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsch/logrep.h +7 -3
  49. data/ext/bigdecimal/math_r/internal/algo/bigmath/carg/formula.h +6 -2
  50. data/ext/bigdecimal/math_r/internal/algo/bigmath/casec/logrep.h +5 -4
  51. data/ext/bigdecimal/math_r/internal/algo/bigmath/casech/logrep.h +3 -1
  52. data/ext/bigdecimal/math_r/internal/algo/bigmath/casin/logrep.h +6 -4
  53. data/ext/bigdecimal/math_r/internal/algo/bigmath/casinh/logrep.h +1 -0
  54. data/ext/bigdecimal/math_r/internal/algo/bigmath/catan/logrep.h +3 -2
  55. data/ext/bigdecimal/math_r/internal/algo/bigmath/catanh/logrep.h +5 -2
  56. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccbrt/branch.h +40 -0
  57. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccbrt/formula.h +5 -2
  58. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccos/eulerf.h +4 -3
  59. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccosh/eulerf.h +4 -3
  60. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccot/eulerf.h +5 -3
  61. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccoth/eulerf.h +4 -2
  62. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsc/eulerf.h +4 -2
  63. data/ext/bigdecimal/math_r/internal/algo/bigmath/ccsch/eulerf.h +5 -3
  64. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp/eulerf.h +10 -7
  65. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexp2/eulerf.h +5 -3
  66. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexpm1/branch.h +13 -0
  67. data/ext/bigdecimal/math_r/internal/algo/bigmath/cexpm1/identity.h +17 -0
  68. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog/branch.h +11 -12
  69. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog10/branch.h +53 -0
  70. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog10/formula.h +4 -3
  71. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog2/branch.h +53 -0
  72. data/ext/bigdecimal/math_r/internal/algo/bigmath/clog2/formula.h +4 -3
  73. data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/eulerf.h +6 -4
  74. data/ext/bigdecimal/math_r/internal/algo/bigmath/cos/ser.h +4 -4
  75. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/eulerf.h +5 -3
  76. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/formula.h +5 -5
  77. data/ext/bigdecimal/math_r/internal/algo/bigmath/cosh/ser.h +4 -3
  78. data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/eulerf.h +5 -3
  79. data/ext/bigdecimal/math_r/internal/algo/bigmath/cot/ser.h +3 -2
  80. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/eulerf.h +4 -2
  81. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/formula.h +1 -0
  82. data/ext/bigdecimal/math_r/internal/algo/bigmath/coth/ser.h +3 -2
  83. data/ext/bigdecimal/math_r/internal/algo/bigmath/cpow/formula.h +7 -6
  84. data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/eulerf.h +4 -2
  85. data/ext/bigdecimal/math_r/internal/algo/bigmath/csc/ser.h +5 -3
  86. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/eulerf.h +5 -3
  87. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/formula.h +2 -2
  88. data/ext/bigdecimal/math_r/internal/algo/bigmath/csch/ser.h +6 -3
  89. data/ext/bigdecimal/math_r/internal/algo/bigmath/csec/eulerf.h +5 -3
  90. data/ext/bigdecimal/math_r/internal/algo/bigmath/csech/eulerf.h +5 -3
  91. data/ext/bigdecimal/math_r/internal/algo/bigmath/csin/eulerf.h +4 -3
  92. data/ext/bigdecimal/math_r/internal/algo/bigmath/csinh/eulerf.h +4 -3
  93. data/ext/bigdecimal/math_r/internal/algo/bigmath/csqrt/branch.h +40 -0
  94. data/ext/bigdecimal/math_r/internal/algo/bigmath/csqrt/formula.h +13 -43
  95. data/ext/bigdecimal/math_r/internal/algo/bigmath/ctan/eulerf.h +4 -3
  96. data/ext/bigdecimal/math_r/internal/algo/bigmath/ctanh/eulerf.h +4 -3
  97. data/ext/bigdecimal/math_r/internal/algo/bigmath/cuberoot/branch.h +18 -0
  98. data/ext/bigdecimal/math_r/internal/algo/bigmath/cuberoot/newton.h +4 -12
  99. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/algo911.h +7 -4
  100. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/cf.h +1 -0
  101. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/ser_inf.h +1 -0
  102. data/ext/bigdecimal/math_r/internal/algo/bigmath/erf/ser_zero.h +1 -0
  103. data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/algo911.h +5 -2
  104. data/ext/bigdecimal/math_r/internal/algo/bigmath/erfc/cf.h +1 -0
  105. data/ext/bigdecimal/math_r/internal/algo/bigmath/escalb/edf.h +2 -0
  106. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/builtin.h +7 -1
  107. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp/edf.h +6 -5
  108. data/ext/bigdecimal/math_r/internal/algo/bigmath/exp2/edf.h +9 -5
  109. data/ext/bigdecimal/math_r/internal/algo/bigmath/expm1/branch.h +13 -0
  110. data/ext/bigdecimal/math_r/internal/algo/bigmath/expm1/identity.h +18 -0
  111. data/ext/bigdecimal/math_r/internal/algo/bigmath/expxt/edf.h +1 -1
  112. data/ext/bigdecimal/math_r/internal/algo/bigmath/f_euler/formula.h +3 -2
  113. data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/l2norm.h +5 -4
  114. data/ext/bigdecimal/math_r/internal/algo/bigmath/hypot/mmm.h +1 -1
  115. data/ext/bigdecimal/math_r/internal/algo/bigmath/ipow/edf.h +6 -4
  116. data/ext/bigdecimal/math_r/internal/algo/bigmath/l2norm/formula.h +6 -1
  117. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/branch.h +6 -2
  118. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/builtin.h +3 -2
  119. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/edf.h +8 -5
  120. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/edom.h +10 -4
  121. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/mercator.h +7 -9
  122. data/ext/bigdecimal/math_r/internal/algo/bigmath/log/ser_okumura.h +4 -1
  123. data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/edf.h +3 -2
  124. data/ext/bigdecimal/math_r/internal/algo/bigmath/log10/mercator.h +9 -9
  125. data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/branch.h +8 -5
  126. data/ext/bigdecimal/math_r/internal/algo/bigmath/log1p/ser_mercator.h +16 -6
  127. data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/branch.h +1 -1
  128. data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/edf.h +3 -2
  129. data/ext/bigdecimal/math_r/internal/algo/bigmath/log2/mercator.h +9 -9
  130. data/ext/bigdecimal/math_r/internal/algo/bigmath/logxt/edf.h +6 -1
  131. data/ext/bigdecimal/math_r/internal/algo/bigmath/pow/formula.h +13 -8
  132. data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm10/edf.h +10 -4
  133. data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm2/edf.h +11 -3
  134. data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/eulerf.h +5 -3
  135. data/ext/bigdecimal/math_r/internal/algo/bigmath/sec/ser.h +6 -4
  136. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/eulerf.h +5 -3
  137. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/formula.h +8 -4
  138. data/ext/bigdecimal/math_r/internal/algo/bigmath/sech/ser.h +5 -3
  139. data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/eulerf.h +5 -2
  140. data/ext/bigdecimal/math_r/internal/algo/bigmath/sin/ser.h +4 -5
  141. data/ext/bigdecimal/math_r/internal/algo/bigmath/sincos/ser.h +9 -2
  142. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/eulerf.h +5 -3
  143. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/formula.h +8 -4
  144. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinh/ser.h +4 -3
  145. data/ext/bigdecimal/math_r/internal/algo/bigmath/sinhcosh/ser.h +10 -3
  146. data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/builtin.h +2 -2
  147. data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/edom.h +1 -0
  148. data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/eulerf.h +5 -3
  149. data/ext/bigdecimal/math_r/internal/algo/bigmath/tan/ser.h +3 -8
  150. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/eulerf.h +5 -3
  151. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/formula.h +7 -3
  152. data/ext/bigdecimal/math_r/internal/algo/bigmath/tanh/ser.h +3 -3
  153. data/ext/bigdecimal/math_r/internal/algo/bigmath/trig/f_euler.h +11 -5
  154. data/ext/bigdecimal/math_r/log.c +2 -2
  155. data/ext/bigdecimal/math_r/math_r/bigdecimal.h +5 -1
  156. data/ext/bigdecimal/math_r/math_r/bigmath.h +2 -0
  157. data/ext/bigdecimal/math_r/math_r/globals.h +1 -1
  158. data/ext/bigdecimal/math_r/math_r.c +5 -3
  159. data/lib/bigdecimal/math_r/const/E_euler.rb +46 -0
  160. data/lib/bigdecimal/math_r/version.rb +1 -1
  161. data/lib/bigdecimal/math_r.rb +1 -0
  162. metadata +20 -10
  163. data/.ruby-version +0 -1
  164. data/lib/bigdecimal/math_r.so +0 -0
@@ -1,7 +1,7 @@
1
1
  VALUE
2
2
  log_branch(VALUE x, VALUE prec, bigmath_func1 log_cb)
3
3
  {
4
- VALUE y = Qundef;
4
+ VALUE y = Qundef, n;
5
5
 
6
6
  x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
7
7
 
@@ -27,8 +27,12 @@ log_branch(VALUE x, VALUE prec, bigmath_func1 log_cb)
27
27
  {
28
28
  const ID add = rb_intern("add");
29
29
  VALUE exp, fra;
30
+
31
+ rb_check_precise(prec);
32
+ n = rb_numdiff_make_n(prec);
33
+
30
34
  fra = rcm2_edf(x, &exp);
31
- exp = rb_funcall1(rb_bigmath_const_log2(prec), '*', exp);
35
+ exp = rb_funcall1(rb_bigmath_const_log2(n), '*', exp);
32
36
  fra = log_cb(fra, prec);
33
37
  y = rb_funcall(exp, add, 2, fra, prec);
34
38
  }
@@ -2,11 +2,12 @@ VALUE
2
2
  log_builtin(VALUE x, VALUE prec)
3
3
  {
4
4
  const ID log = rb_intern("log");
5
- VALUE y;
5
+ VALUE y, n;
6
6
 
7
7
  rb_check_precise(prec);
8
+ n = rb_numdiff_make_n(prec);
8
9
 
9
- y = rb_funcall(rb_mBigMath, log, 2, x, prec);
10
+ y = rb_funcall(rb_mBigMath, log, 2, x, n);
10
11
 
11
12
  return rb_num_round(y, prec);
12
13
  }
@@ -1,10 +1,13 @@
1
1
  VALUE
2
2
  log_edf(VALUE x, VALUE prec)
3
3
  {
4
- VALUE fra = Qundef, exp = Qundef, y = Qundef;
5
- fra = rcm2_edf(x, &exp);
6
- fra = logxt_edf(fra, INT2FIX(2), prec);
7
- y = rb_funcall1(exp, '+', fra);
8
- y = rb_funcall1(y, '*', rb_bigmath_const_log2(prec));
4
+ VALUE y = Qundef, n;
5
+
6
+ rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
8
+
9
+ y = logxt_edf(x, INT2FIX(2), n);
10
+ y = rb_funcall1(y, '*', rb_bigmath_const_log2(n));
11
+
9
12
  return rb_num_round(y, prec);
10
13
  }
@@ -1,10 +1,16 @@
1
1
  VALUE
2
2
  log_edom(VALUE x, VALUE prec)
3
3
  {
4
- VALUE y, pi = rb_bigmath_const_pi(prec);
5
- x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
4
+ VALUE y, pi = rb_bigmath_const_pi(prec), n;
5
+
6
+ rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
8
+
9
+ x = rb_num_canonicalize(x, n, ARG_REAL, ARG_RAWVALUE);
6
10
  RUBY_ASSERT (rb_num_negative_p(x));
7
11
  x = rb_num_uminus(x);
8
- y = rb_bigmath_log(x, prec);
9
- return rb_Complex(y, pi);
12
+ y = rb_bigmath_log(x, n);
13
+ y = rb_Complex(y, pi);
14
+
15
+ return rb_num_round(y, prec);
10
16
  }
@@ -17,18 +17,16 @@ VALUE
17
17
  log_mercator(VALUE x, VALUE prec)
18
18
  {
19
19
  const ID div = rb_intern("div");
20
- VALUE fra = Qundef, exp = Qundef, y = Qundef;
21
- fra = rcm2_edf(x, &exp);
20
+ VALUE temp = Qundef, y = Qundef, n;
22
21
 
23
22
  rb_check_precise(prec);
23
+ n = rb_numdiff_make_n(prec);
24
24
 
25
- y = rb_funcall1(fra, '-', INT2FIX(1));
26
- fra = rb_funcall(y, div, 2, fra, prec);
27
- fra = rb_num_uminus(fra);
28
- fra = log1p_ser_mercator(fra, prec);
29
- fra = rb_num_uminus(fra);
25
+ y = rb_funcall1(temp, '-', INT2FIX(1));
26
+ temp = rb_funcall(y, div, 2, temp, n);
27
+ temp = rb_num_uminus(temp);
28
+ temp = log1p_ser_mercator(temp, n);
29
+ y = rb_num_uminus(temp);
30
30
 
31
- exp = rb_funcall1(exp, '*', rb_bigmath_const_log2(prec));
32
- y = rb_funcall1(exp, '+', fra);
33
31
  return rb_num_round(y, prec);
34
32
  }
@@ -9,8 +9,11 @@ log_ser_okumura(VALUE x, VALUE prec)
9
9
  bool inv;
10
10
  VALUE one = BIG_ONE;
11
11
  VALUE two = rb_BigDecimal1(INT2FIX(2));
12
- VALUE n = rb_numdiff_make_n(prec), m;
12
+ VALUE n, m;
13
13
  VALUE k, x2, i, s, d, y;
14
+
15
+ rb_check_precise(prec);
16
+ n = rb_numdiff_make_n(prec);
14
17
 
15
18
  inv = RTEST(rb_num_coerce_cmp(x, INT2FIX(1), '>'));
16
19
  if (inv)
@@ -1,11 +1,12 @@
1
1
  VALUE
2
2
  log10_edf(VALUE x, VALUE prec)
3
3
  {
4
- VALUE y = Qundef;
4
+ VALUE y = Qundef, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- y = logxt_edf(x, INT2FIX(10), prec);
9
+ y = logxt_edf(x, INT2FIX(10), n);
9
10
 
10
11
  return rb_num_round(y, prec);
11
12
  }
@@ -17,19 +17,19 @@ VALUE
17
17
  log10_mercator(VALUE x, VALUE prec)
18
18
  {
19
19
  const ID div = rb_intern("div");
20
- VALUE fra = Qundef, exp = Qundef, y = Qundef;
20
+ VALUE temp = Qundef, y = Qundef, n;
21
21
 
22
22
  rb_check_precise(prec);
23
+ n = rb_numdiff_make_n(prec);
23
24
 
24
- fra = rcm10_edf(x, &exp);
25
+ y = rb_funcall1(x, '-', INT2FIX(1));
26
+ temp = rb_funcall(y, div, 2, temp, n);
27
+ temp = rb_num_uminus(temp);
28
+ temp = log1p_ser_mercator(temp, n);
29
+ temp = rb_num_uminus(temp);
30
+ temp = rb_funcall(temp, div, 2, rb_bigmath_const_log10(n), n);
25
31
 
26
- y = rb_funcall1(fra, '-', INT2FIX(1));
27
- fra = rb_funcall(y, div, 2, fra, prec);
28
- fra = rb_num_uminus(fra);
29
- fra = log1p_ser_mercator(fra, prec);
30
- fra = rb_num_uminus(fra);
31
- fra = rb_funcall(fra, div, 2, rb_bigmath_const_log10(prec), prec);
32
+ y = temp;
32
33
 
33
- y = rb_funcall1(exp, '+', fra);
34
34
  return rb_num_round(y, prec);
35
35
  }
@@ -1,8 +1,8 @@
1
1
  VALUE
2
- log1p_branch(VALUE x, VALUE prec, bigmath_func1 cb)
2
+ log1p_branch(VALUE x, VALUE prec, bigmath_func1 log1p_cb)
3
3
  {
4
4
  VALUE y = Qundef;
5
- VALUE one_thousand = rb_Rational(INT2FIX(1), INT2FIX(1000));
5
+ VALUE one_thousand = rb_Rational(INT2FIX(1), INT2FIX(1000)), n;
6
6
  const ID geq = rb_intern_const(">=");
7
7
  const ID gt = rb_intern_const(">");
8
8
 
@@ -13,20 +13,23 @@ log1p_branch(VALUE x, VALUE prec, bigmath_func1 cb)
13
13
  if (rb_num_nan_p(x))
14
14
  y = BIG_NAN;
15
15
  else
16
- y = log_branch(x, prec, cb);
16
+ y = log_branch(x, prec, log1p_cb);
17
17
  }
18
18
  if (y == Qundef)
19
19
  {
20
20
  if (rb_num_zero_p(x))
21
21
  y = BIG_ZERO;
22
22
  else if (RTEST(rb_num_coerce_cmp(one_thousand, rb_num_abs(x), geq)))
23
- y = cb(x, prec);
23
+ y = log1p_cb(x, prec);
24
24
  else if (RTEST(rb_num_coerce_cmp(INT2FIX(-1), x, gt)))
25
25
  y = BIG_NAN;
26
26
  else
27
27
  {
28
+ rb_check_precise(prec);
29
+ n = rb_numdiff_make_n(prec);
30
+
28
31
  x = rb_funcall1(x, '+', BIG_ONE);
29
- y = rb_bigmath_log(x, prec);
32
+ y = rb_bigmath_log(x, n);
30
33
  y = rb_num_round(y, prec);
31
34
  }
32
35
  }
@@ -3,15 +3,25 @@ log1p_ser_mercator(VALUE x, VALUE prec)
3
3
  {
4
4
  const ID div = rb_intern("div");
5
5
  const ID mult = rb_intern("mult");
6
- VALUE n = rb_numdiff_make_n(prec);
7
- VALUE one = BIG_ONE;
8
- VALUE w = rb_num_canonicalize(x, n, ARG_REAL, ARG_RAWVALUE);
9
- VALUE t = one;
10
- VALUE d = BIG_ONE;
11
- VALUE y = BIG_ZERO;
6
+ VALUE n;
7
+ VALUE one;
8
+ VALUE w;
9
+ VALUE t;
10
+ VALUE d;
11
+ VALUE y;
12
12
  int sign = 1;
13
13
  VALUE m = Qundef;
14
14
 
15
+ rb_check_precise(prec);
16
+ n = rb_numdiff_make_n(prec);
17
+
18
+ one = BIG_ONE;
19
+ t = one;
20
+ d = BIG_ONE;
21
+ y = BIG_ZERO;
22
+
23
+ w = rb_num_canonicalize(x, n, ARG_REAL, ARG_RAWVALUE);
24
+
15
25
  while (rb_numdiff_condition_p(y, d, n, &m))
16
26
  {
17
27
  d = rb_funcall(w, div, 2, t, m);
@@ -29,7 +29,7 @@ log2_branch(VALUE x, VALUE prec, bigmath_func1 log2_cb)
29
29
  VALUE exp, fra;
30
30
  fra = rcm2_edf(x, &exp);
31
31
  exp = rb_BigDecimal1(exp);
32
- fra = log2_cb(fra, prec);
32
+ fra = log2_cb(fra, rb_numdiff_make_n(prec));
33
33
  y = rb_funcall(exp, add, 2, fra, prec);
34
34
  }
35
35
  else
@@ -1,11 +1,12 @@
1
1
  VALUE
2
2
  log2_edf(VALUE x, VALUE prec)
3
3
  {
4
- VALUE y = Qundef;
4
+ VALUE y = Qundef, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- y = logxt_edf(x, INT2FIX(2), prec);
9
+ y = logxt_edf(x, INT2FIX(2), n);
9
10
 
10
11
  return rb_num_round(y, prec);
11
12
  }
@@ -17,19 +17,19 @@ VALUE
17
17
  log2_mercator(VALUE x, VALUE prec)
18
18
  {
19
19
  const ID div = rb_intern("div");
20
- VALUE fra = Qundef, exp = Qundef, y = Qundef;
20
+ VALUE temp = Qundef, y = Qundef, n;
21
21
 
22
22
  rb_check_precise(prec);
23
+ n = rb_numdiff_make_n(prec);
23
24
 
24
- fra = rcm2_edf(x, &exp);
25
+ y = rb_funcall1(x, '-', INT2FIX(1));
26
+ temp = rb_funcall(y, div, 2, temp, n);
27
+ temp = rb_num_uminus(temp);
28
+ temp = log1p_ser_mercator(temp, n);
29
+ temp = rb_num_uminus(temp);
30
+ temp = rb_funcall(temp, div, 2, rb_bigmath_const_log2(n), n);
25
31
 
26
- y = rb_funcall1(fra, '-', INT2FIX(1));
27
- fra = rb_funcall(y, div, 2, fra, prec);
28
- fra = rb_num_uminus(fra);
29
- fra = log1p_ser_mercator(fra, prec);
30
- fra = rb_num_uminus(fra);
31
- fra = rb_funcall(fra, div, 2, rb_bigmath_const_log2(prec), prec);
32
+ y = temp;
32
33
 
33
- y = rb_funcall1(exp, '+', fra);
34
34
  return rb_num_round(y, prec);
35
35
  }
@@ -4,7 +4,12 @@ logxt_edf(VALUE x, VALUE t, VALUE prec)
4
4
  const ID mult = rb_intern("mult");
5
5
  VALUE a, b, s, one_half, n, m;
6
6
 
7
+ rb_check_precise(prec);
7
8
  n = rb_numdiff_make_n(prec);
9
+
10
+ if (!rb_num_finite_p(x) || !rb_num_finite_p(t))
11
+ return BIG_NAN;
12
+
8
13
  a = rb_num_canonicalize(x, n, ARG_REAL, ARG_RAWVALUE);
9
14
  b = BIG_ONE;
10
15
  s = BIG_ZERO;
@@ -29,5 +34,5 @@ logxt_edf(VALUE x, VALUE t, VALUE prec)
29
34
  RB_GC_GUARD(s);
30
35
  RB_GC_GUARD(one_half);
31
36
 
32
- return s;
37
+ return rb_num_round(s, prec);
33
38
  }
@@ -1,30 +1,35 @@
1
1
  VALUE
2
2
  pow_formula(VALUE x, VALUE y, VALUE prec)
3
3
  {
4
- VALUE a = Qundef;
4
+ VALUE a = Qundef, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
8
+
7
9
  if (!rb_num_real_p(x))
8
- rb_raise(rb_eTypeError, "not a Real");
10
+ goto not_a_real_error;
9
11
  if (rb_num_zero_p(rb_num_real(x)))
10
12
  a = BIG_ONE;
11
13
  if (TYPE(y) == T_FIXNUM || TYPE(y) == T_BIGNUM)
12
14
  {
13
15
  if (rb_num_positive_p(rb_num_real(x)))
14
- a = ipow_edf(x, y, prec);
16
+ a = ipow_edf(x, y, n);
15
17
  else // if (rb_num_negative_p(rb_num_real(x)))
16
- a = rb_num_uminus(ipow_edf(rb_num_abs(x), y, prec));
18
+ a = rb_num_uminus(ipow_edf(rb_num_abs(x), y, n));
17
19
  }
18
20
  else if (rb_num_real_p(y))
19
21
  {
20
- a = rb_bigmath_log(rb_num_abs(x), prec);
22
+ a = rb_bigmath_log(rb_num_abs(x), n);
21
23
  a = rb_funcall1(y, '*', a);
22
- a = rb_bigmath_exp(a, prec);
24
+ a = rb_bigmath_exp(a, n);
23
25
  if (rb_num_negative_p(x))
24
26
  a = rb_num_uminus(a);
25
27
  }
26
28
  else
27
- rb_raise(rb_eTypeError, "not a Real");
29
+ goto not_a_real_error;
30
+
31
+ return rb_num_round(a, prec);
28
32
 
29
- return a;
33
+ not_a_real_error:
34
+ rb_raise(rb_eTypeError, "not a Real");
30
35
  }
@@ -4,7 +4,9 @@ rcm10_edf(VALUE x, VALUE *reso)
4
4
  VALUE fra = x; *reso = INT2FIX(0);
5
5
  if (rb_num_nonzero_p(fra) && rb_num_finite_p(fra))
6
6
  {
7
- long resov = 0;
7
+ const ID succ = rb_intern("succ");
8
+ const ID pred = rb_intern("pred");
9
+ VALUE resov = LONG2FIX(0);
8
10
  bool has_sign = RTEST(rb_num_coerce_cmp(x, INT2FIX(0), '<'));
9
11
  VALUE rat_ten = rb_rational_new1(INT2FIX(10));
10
12
  fra = rb_Rational1(fra);
@@ -15,7 +17,9 @@ rcm10_edf(VALUE x, VALUE *reso)
15
17
  while (RTEST(rb_num_coerce_cmp(fra, INT2FIX(10), rb_intern(">="))))
16
18
  {
17
19
  fra = rb_funcall1(fra, '/', rat_ten);
18
- resov++;
20
+ resov = TYPE(resov) == T_FIXNUM ?
21
+ LONG2FIX(FIX2LONG(resov) + 1) :
22
+ rb_funcall(resov, succ, 0);
19
23
  }
20
24
  }
21
25
  else if (RTEST(rb_num_coerce_cmp(fra, INT2FIX(1), '<')))
@@ -23,12 +27,14 @@ rcm10_edf(VALUE x, VALUE *reso)
23
27
  while (RTEST(rb_num_coerce_cmp(fra, INT2FIX(1), '<')))
24
28
  {
25
29
  fra = rb_funcall1(fra, '*', rat_ten);
26
- resov--;
30
+ resov = TYPE(resov) == T_FIXNUM ?
31
+ LONG2FIX(FIX2LONG(resov) - 1) :
32
+ rb_funcall(resov, pred, 0);
27
33
  }
28
34
  }
29
35
  if (has_sign)
30
36
  fra = rb_num_uminus(fra);
31
- *reso = LONG2FIX(resov);
37
+ *reso = resov;
32
38
  }
33
39
  return fra;
34
40
  }
@@ -1,10 +1,14 @@
1
1
  VALUE
2
2
  rcm2_edf(VALUE x, VALUE *reso)
3
3
  {
4
+
4
5
  VALUE fra = x; *reso = INT2FIX(0);
6
+
5
7
  if (rb_num_nonzero_p(fra) && rb_num_finite_p(fra))
6
8
  {
7
- long resov = 0;
9
+ const ID succ = rb_intern("succ");
10
+ const ID pred = rb_intern("pred");
11
+ VALUE resov = LONG2FIX(0);
8
12
  bool has_sign = RTEST(rb_num_coerce_cmp(x, INT2FIX(0), '<'));
9
13
  VALUE rat_two = rb_rational_new1(INT2FIX(2));
10
14
  fra = rb_Rational1(fra);
@@ -15,7 +19,9 @@ rcm2_edf(VALUE x, VALUE *reso)
15
19
  while (RTEST(rb_num_coerce_cmp(INT2FIX(2), fra, rb_intern("<="))))
16
20
  {
17
21
  fra = rb_funcall1(fra, '/', rat_two);
18
- resov++;
22
+ TYPE(resov) == T_FIXNUM ?
23
+ LONG2FIX(FIX2LONG(resov) + 1) :
24
+ rb_funcall(resov, succ, 0);
19
25
  }
20
26
  }
21
27
  else
@@ -23,7 +29,9 @@ rcm2_edf(VALUE x, VALUE *reso)
23
29
  while (RTEST(rb_num_coerce_cmp(INT2FIX(1), fra, '>')))
24
30
  {
25
31
  fra = rb_funcall1(fra, '*', rat_two);
26
- resov--;
32
+ TYPE(resov) == T_FIXNUM ?
33
+ LONG2FIX(FIX2LONG(resov) - 1) :
34
+ rb_funcall(resov, pred, 0);
27
35
  }
28
36
  }
29
37
  if (has_sign)
@@ -1,11 +1,13 @@
1
1
  VALUE
2
2
  sec_eulerf(VALUE z, VALUE prec)
3
3
  {
4
- VALUE w;
4
+ VALUE w, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- w = trig_f_euler(mf_cos, rb_ImaginaryZ(z, SIGN_PLUS), prec);
9
+ w = trig_f_euler(mf_cos, rb_ImaginaryZ(z, SIGN_PLUS), n);
10
+ w = rb_num_canonicalize(w, n, ARG_REAL, ARG_RECIPROCAL);
9
11
 
10
- return rb_num_canonicalize(w, prec, ARG_REAL, ARG_RECIPROCAL);
12
+ return rb_num_round(w, prec);
11
13
  }
@@ -1,11 +1,13 @@
1
1
  VALUE
2
2
  sec_ser(VALUE x, VALUE prec)
3
3
  {
4
- VALUE cos;
4
+ VALUE sec, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- rb_bigmath_sincos(x, prec, NULL, &cos);
9
-
10
- return rb_num_canonicalize(cos, prec, ARG_REAL, ARG_RECIPROCAL);
9
+ rb_bigmath_sincos(x, n, NULL, &sec);
10
+ sec = rb_num_canonicalize(sec, n, ARG_REAL, ARG_RECIPROCAL);
11
+
12
+ return rb_num_round(sec, prec);
11
13
  }
@@ -1,11 +1,13 @@
1
1
  VALUE
2
2
  sech_eulerf(VALUE x, VALUE prec)
3
3
  {
4
- VALUE y;
4
+ VALUE y = Qundef, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- y = trig_f_euler(mf_cos, x, prec);
9
+ y = trig_f_euler(mf_cos, x, n);
10
+ y = rb_num_canonicalize(y, n, ARG_REAL, ARG_RECIPROCAL);
9
11
 
10
- return rb_num_canonicalize(y, prec, ARG_REAL, ARG_RECIPROCAL);
12
+ return rb_num_round(y, prec);
11
13
  }
@@ -2,9 +2,13 @@ VALUE
2
2
  sech_formula(VALUE x, VALUE prec)
3
3
  {
4
4
  const ID div = rb_intern("div");
5
- VALUE n = rb_numdiff_make_n(prec);
6
- VALUE t = rb_bigmath_exp(x, n), y = Qundef;
7
- VALUE two = rb_BigDecimal1(INT2FIX(2));
5
+ VALUE n, t, two, y = Qundef;
6
+
7
+ rb_check_precise(prec);
8
+ n = rb_numdiff_make_n(prec);
9
+
10
+ t = rb_bigmath_exp(x, n);
11
+ two = rb_BigDecimal1(INT2FIX(2));
8
12
 
9
13
  if (TYPE(t) == T_FIXNUM || TYPE(t) == T_BIGNUM)
10
14
  {
@@ -16,7 +20,7 @@ sech_formula(VALUE x, VALUE prec)
16
20
  y = BIG_ZERO;
17
21
  else
18
22
  {
19
- y = rb_num_canonicalize(t, prec, ARG_REAL, ARG_RECIPROCAL);
23
+ y = rb_num_canonicalize(t, n, ARG_REAL, ARG_RECIPROCAL);
20
24
  y = rb_funcall1(t, '+', y);
21
25
  y = rb_funcall(two, div, 2, y, prec);
22
26
  }
@@ -1,11 +1,13 @@
1
1
  VALUE
2
2
  sech_ser(VALUE x, VALUE prec)
3
3
  {
4
- VALUE y = Qundef;
4
+ VALUE y = Qundef, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- sinhcosh_ser(x, prec, NULL, &y);
9
+ sinhcosh_ser(x, n, NULL, &y);
10
+ y = rb_num_canonicalize(y, n, ARG_REAL, ARG_RECIPROCAL);
9
11
 
10
- return rb_num_canonicalize(y, prec, ARG_REAL, ARG_RECIPROCAL);
12
+ return rb_num_round(y, prec);
11
13
  }
@@ -2,10 +2,13 @@ VALUE
2
2
  sin_eulerf(VALUE z, VALUE prec)
3
3
  {
4
4
  const ID sin = rb_intern("sin");
5
+ VALUE n;
5
6
 
6
7
  rb_check_precise(prec);
8
+ n = rb_numdiff_make_n(prec);
7
9
 
8
- z = trig_f_euler(sin, rb_ImaginaryZ(z, SIGN_PLUS), prec);
10
+ z = trig_f_euler(sin, rb_ImaginaryZ(z, SIGN_PLUS), n);
11
+ z = rb_num_real(z);
9
12
 
10
- return rb_num_real(z);
13
+ return rb_num_round(z, prec);
11
14
  }
@@ -1,13 +1,12 @@
1
1
  VALUE
2
2
  sin_ser(VALUE x, VALUE prec)
3
3
  {
4
- VALUE sin;
4
+ VALUE sin, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- rb_bigmath_sincos(x, prec, &sin, NULL);
9
+ rb_bigmath_sincos(x, n, &sin, NULL);
9
10
 
10
- sin = rb_num_round(sin, prec);
11
-
12
- return sin;
11
+ return rb_num_round(sin, prec);
13
12
  }
@@ -4,23 +4,28 @@ sincos_ser(VALUE x, VALUE prec, VALUE *sin, VALUE *cos)
4
4
  const ID div = rb_intern("div");
5
5
  VALUE n, m, f, w, a, y;
6
6
  long i = 0;
7
-
7
+
8
8
  if (sin == NULL && cos == NULL)
9
9
  return;
10
-
10
+
11
+
11
12
  if (!rb_num_finite_p(x))
12
13
  {
13
14
  if (sin != NULL) *sin = BIG_NAN;
14
15
  if (cos != NULL) *cos = BIG_NAN;
15
16
  return;
16
17
  }
18
+
19
+ rb_check_precise(prec);
17
20
  n = rb_numdiff_make_n(prec);
21
+
18
22
  f = BIG_ONE;
19
23
  w = BIG_ONE;
20
24
  a = BIG_ONE;
21
25
  y = BIG_ZERO;
22
26
  if (sin != NULL) *sin = BIG_ZERO;
23
27
  if (cos != NULL) *cos = BIG_ZERO;
28
+
24
29
  while (rb_numdiff_condition_p(y, a, n, &m))
25
30
  {
26
31
  a = rb_funcall(w, div, 2, f, m);
@@ -41,10 +46,12 @@ sincos_ser(VALUE x, VALUE prec, VALUE *sin, VALUE *cos)
41
46
  w = rb_funcall1(w, '*', x);
42
47
  f = rb_funcall1(f, '*', LONG2NUM(++i));
43
48
  }
49
+
44
50
  RB_GC_GUARD(f);
45
51
  RB_GC_GUARD(w);
46
52
  RB_GC_GUARD(a);
47
53
  RB_GC_GUARD(y);
54
+
48
55
  if (sin != NULL) RB_GC_GUARD(*sin);
49
56
  if (cos != NULL) RB_GC_GUARD(*cos);
50
57
  }
@@ -1,11 +1,13 @@
1
1
  VALUE
2
2
  sinh_eulerf(VALUE x, VALUE prec)
3
3
  {
4
- VALUE y;
4
+ VALUE y = Qundef, n;
5
5
 
6
6
  rb_check_precise(prec);
7
+ n = rb_numdiff_make_n(prec);
7
8
 
8
- y = rb_ImaginaryZ(trig_f_euler(mf_sin, x, prec), SIGN_PLUS);
9
+ y = rb_ImaginaryZ(trig_f_euler(mf_sin, x, n), SIGN_PLUS);
10
+ y = rb_num_real(y);
9
11
 
10
- return rb_num_real(y);
12
+ return rb_num_round(y, prec);
11
13
  }
@@ -2,11 +2,15 @@ VALUE
2
2
  sinh_formula(VALUE x, VALUE prec)
3
3
  {
4
4
  const ID div = rb_intern("div");
5
- VALUE n = rb_numdiff_make_n(prec);
6
- VALUE t = rb_bigmath_exp(x, n), y = Qundef;
7
- VALUE two = rb_BigDecimal1(INT2FIX(2));
5
+ VALUE n, t, y = Qundef, two;
8
6
  int sign;
9
7
 
8
+ rb_check_precise(prec);
9
+ n = rb_numdiff_make_n(prec);
10
+
11
+ t = rb_bigmath_exp(x, n);
12
+ two = rb_BigDecimal1(INT2FIX(2));
13
+
10
14
  if (TYPE(t) == T_FIXNUM || TYPE(t) == T_BIGNUM)
11
15
  {
12
16
  y = rb_Rational(INT2FIX(1), t);
@@ -17,7 +21,7 @@ sinh_formula(VALUE x, VALUE prec)
17
21
  y = sign == 1 ? BIG_INF : BIG_MINUS_INF;
18
22
  else
19
23
  {
20
- y = rb_num_canonicalize(t, prec, ARG_REAL, ARG_RECIPROCAL);
24
+ y = rb_num_canonicalize(t, n, ARG_REAL, ARG_RECIPROCAL);
21
25
  y = rb_funcall1(t, '-', y);
22
26
  y = rb_funcall(y, div, 2, two, prec);
23
27
  }