bigdecimal-math_r 0.2.6 → 0.2.8
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 +4 -4
- data/README.md +2 -1
- data/changelog.md +9 -0
- data/ext/bigdecimal/math_r/const.c +0 -8
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/branch.h +1 -1
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/edom.h +4 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacos/branch.h +15 -7
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacosh/branch.h +6 -4
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cacsch/branch.h +0 -2
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casec/branch.h +8 -4
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casech/branch.h +2 -10
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casin/branch.h +23 -8
- data/ext/bigdecimal/math_r/internal/algo/bigmath/casinh/branch.h +24 -29
- data/ext/bigdecimal/math_r/internal/algo/bigmath/catan/branch.h +12 -9
- data/ext/bigdecimal/math_r/internal/algo/bigmath/catanh/branch.h +14 -7
- data/ext/bigdecimal/math_r/internal/algo/bigmath/ccosh/branch.h +3 -1
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cpow/formula.h +6 -2
- data/ext/bigdecimal/math_r/internal/algo/bigmath/rcm2/edf.h +2 -2
- data/ext/bigdecimal/math_r/internal/algo/bigmath/trig/f_euler.h +9 -3
- data/lib/bigdecimal/math_r/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e81ef8bf762b9147ddb484f578dff41f43fbede81f4b8e875b554528540dc299
|
|
4
|
+
data.tar.gz: bc13ee261dc7a056eef1eb231f1059190bdf97c8cde0ede2e2206f6c335ede09
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ce5aadd6303fea558e215f3a1a9b51953246fe192f0370958c67e247f59483f537944b56a135537c11b6791a2fe495163771c35159b75a230a705991a9d4a61
|
|
7
|
+
data.tar.gz: ef35daded47e2bf1d127fffe99f0ecb00b0c7fe814cf85b9fa39ac083a50fe396ac3de6c48585cfd428edffe0acc4436cb8aef1ed9ce6d809e2b8068ec65c7fc
|
data/README.md
CHANGED
|
@@ -23,7 +23,8 @@ Mathematical functions are compatible with both real and complex solutions.
|
|
|
23
23
|
|
|
24
24
|
Constants:
|
|
25
25
|
```
|
|
26
|
-
:E (Constant e)
|
|
26
|
+
:E (Constant e)
|
|
27
|
+
:EulerGamma (Euler-Mascheroni Constant)
|
|
27
28
|
:LOG2 (Natural logarithm of 2)
|
|
28
29
|
:LOG_PI (Natural logarithm of pi)
|
|
29
30
|
:LOG10 (Natural logarithm of 10)
|
data/changelog.md
CHANGED
|
@@ -7,6 +7,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.7] - 2025-10-XX
|
|
11
|
+
|
|
12
|
+
### Fix
|
|
13
|
+
- rcm2_edf(): Ignore Increase/Declease for exponent
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- BigMathR#EulerGamma
|
|
17
|
+
- BigMathR::Const::EulerGamma#borwein_bailey
|
|
18
|
+
|
|
10
19
|
## [0.2.6] - 2025-10-XX
|
|
11
20
|
|
|
12
21
|
### Fix
|
|
@@ -54,7 +54,6 @@ __impl_const_e(VALUE unused_obj, VALUE prec)
|
|
|
54
54
|
return rb_bigmath_const_e(prec);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
#if 0
|
|
58
57
|
/**
|
|
59
58
|
* The Euler-Mascheroni constant gamma.
|
|
60
59
|
* @example
|
|
@@ -69,7 +68,6 @@ __impl_const_euler_gamma(VALUE unused_obj, VALUE prec)
|
|
|
69
68
|
{
|
|
70
69
|
return rb_bigmath_const_euler_gamma(prec);
|
|
71
70
|
}
|
|
72
|
-
#endif
|
|
73
71
|
|
|
74
72
|
/**
|
|
75
73
|
* The natural logarithm of 2.
|
|
@@ -165,7 +163,6 @@ __impl_const_e_napier(VALUE unused_obj, VALUE prec)
|
|
|
165
163
|
return E_napier(prec);
|
|
166
164
|
}
|
|
167
165
|
|
|
168
|
-
#if 0
|
|
169
166
|
/**
|
|
170
167
|
* Implement by Borwein-Bailey's formula (Brent-McMillan type formula)
|
|
171
168
|
*
|
|
@@ -182,7 +179,6 @@ __impl_const_euler_gamma_borwein_bailey(VALUE unused_obj, VALUE prec)
|
|
|
182
179
|
{
|
|
183
180
|
return EulerGamma_borwein_bailey(prec);
|
|
184
181
|
}
|
|
185
|
-
#endif
|
|
186
182
|
|
|
187
183
|
/**
|
|
188
184
|
* Implement by BBP's formula (Borwein and Bailey 2002)
|
|
@@ -208,9 +204,7 @@ InitVM_Const(void)
|
|
|
208
204
|
{
|
|
209
205
|
rb_define_module_function(rb_mBigMathR, "PI", __impl_const_pi, 1);
|
|
210
206
|
rb_define_module_function(rb_mBigMathR, "E", __impl_const_e, 1);
|
|
211
|
-
#if 0
|
|
212
207
|
rb_define_module_function(rb_mBigMathR, "EulerGamma", __impl_const_euler_gamma, 1);
|
|
213
|
-
#endif
|
|
214
208
|
rb_define_module_function(rb_mBigMathR, "LOG2", __impl_const_log2, 1);
|
|
215
209
|
rb_define_module_function(rb_mBigMathR, "LOG_PI", __impl_const_log_pi, 1);
|
|
216
210
|
rb_define_module_function(rb_mBigMathR, "LOG10", __impl_const_log10, 1);
|
|
@@ -220,12 +214,10 @@ InitVM_Const(void)
|
|
|
220
214
|
rb_define_module_function(rb_mConstPI, "machin", __impl_const_pi_machin, 1);
|
|
221
215
|
rb_define_module_function(rb_mConstE, "napier", __impl_const_e_napier, 1);
|
|
222
216
|
rb_define_module_function(rb_mConstE, "euler_number", __impl_const_e_napier, 1);
|
|
223
|
-
#if 0
|
|
224
217
|
rb_define_module_function(rb_mConstEulerGamma, "borwein_bailey",
|
|
225
218
|
__impl_const_euler_gamma_borwein_bailey, 1);
|
|
226
219
|
rb_define_module_function(rb_mConstEulerGamma, "brent_mcmillan",
|
|
227
220
|
__impl_const_euler_gamma_borwein_bailey, 1);
|
|
228
|
-
#endif
|
|
229
221
|
rb_define_module_function(rb_mConstLOG2, "bbp2002", __impl_const_log2_bbp2002, 1);
|
|
230
222
|
}
|
|
231
223
|
|
|
@@ -14,7 +14,7 @@ asec_branch(VALUE x, VALUE prec, bigmath_func1 asec_cb)
|
|
|
14
14
|
y = rb_funcall(rb_bigmath_const_pi(prec), div, 2, INT2FIX(2), prec);
|
|
15
15
|
else if (rb_num_equal_p(x, INT2FIX(-1)))
|
|
16
16
|
y = rb_bigmath_const_pi(prec);
|
|
17
|
-
else if (rb_num_equal_p(x, INT2FIX(
|
|
17
|
+
else if (rb_num_equal_p(x, INT2FIX(1)))
|
|
18
18
|
y = BIG_ZERO;
|
|
19
19
|
else if (rb_num_domain_p(p_domain, x) || rb_num_domain_p(m_domain, x))
|
|
20
20
|
y = asec_cb(x, prec);
|
|
@@ -8,9 +8,13 @@ asec_edom(VALUE x, VALUE prec)
|
|
|
8
8
|
|
|
9
9
|
x = rb_num_canonicalize(x, n, ARG_REAL, ARG_RECIPROCAL);
|
|
10
10
|
t = rb_funcall1(BIG_ONE, '-', rb_funcall1(x, '*', x));
|
|
11
|
+
// Bug-fix: Below, if the argument is -0.0, the calculation is Infinity-Infinity, resulting in NaN.
|
|
11
12
|
t = rb_funcall1(rb_bigmath_sqrt(rb_num_uminus(t), n), '+', x);
|
|
12
13
|
arg = rb_num_negative_p(x) ? rb_bigmath_const_pi(n) : BIG_ZERO;
|
|
13
14
|
imag = rb_bigmath_log(rb_num_abs(t), n);
|
|
15
|
+
// Bug-Fix: Set to -Infinity if NaN
|
|
16
|
+
if (rb_num_nan_p(imag))
|
|
17
|
+
imag = BIG_MINUS_INF;
|
|
14
18
|
y = rb_Complex(arg, imag);
|
|
15
19
|
|
|
16
20
|
return rb_num_round(y, prec);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
VALUE
|
|
2
2
|
cacos_branch(VALUE z, VALUE prec, bigmath_func1 cacos_cb)
|
|
3
3
|
{
|
|
4
|
+
const ID mult = rb_intern("mult");
|
|
5
|
+
const ID div = rb_intern("div");
|
|
4
6
|
int z_re_inf = rb_num_infinite_p(rb_num_real(z));
|
|
5
7
|
int z_im_inf = rb_num_infinite_p(rb_num_imag(z));
|
|
6
8
|
|
|
@@ -14,20 +16,26 @@ cacos_branch(VALUE z, VALUE prec, bigmath_func1 cacos_cb)
|
|
|
14
16
|
(rb_num_zero_p(rb_num_imag(z)) &&
|
|
15
17
|
z_re_inf == 1) ?
|
|
16
18
|
BIG_ZERO : rb_bigmath_const_pi(prec);
|
|
17
|
-
VALUE imag =
|
|
19
|
+
VALUE imag = BIG_MINUS_INF;
|
|
18
20
|
return rb_Complex(real, imag);
|
|
19
21
|
}
|
|
20
22
|
else if (z_re_inf == 0 && z_im_inf != 0)
|
|
21
23
|
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return rb_Complex(
|
|
24
|
+
VALUE real = rb_bigmath_const_pi(prec);
|
|
25
|
+
VALUE imag = z_im_inf == 1 ? BIG_MINUS_INF : BIG_INF;
|
|
26
|
+
if (!rb_num_negative_p(rb_num_real(z)))
|
|
27
|
+
real = rb_funcall(real, div, 2, INT2FIX(2), prec);
|
|
28
|
+
return rb_Complex(real, imag);
|
|
27
29
|
}
|
|
28
30
|
else
|
|
29
31
|
{
|
|
30
|
-
|
|
32
|
+
VALUE real = rb_bigmath_const_pi(prec);
|
|
33
|
+
VALUE imag = z_im_inf == -1 ? BIG_INF : BIG_MINUS_INF;
|
|
34
|
+
real = z_re_inf == -1 ?
|
|
35
|
+
rb_funcall(real, mult, 2,
|
|
36
|
+
rb_rational_new(INT2FIX(3), INT2FIX(4)), prec) :
|
|
37
|
+
rb_funcall(real, div, 2, INT2FIX(4), prec);
|
|
38
|
+
return rb_Complex(real, imag);
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
else
|
|
@@ -17,14 +17,16 @@ cacosh_branch(VALUE z, VALUE prec, bigmath_func1 cacosh_cb)
|
|
|
17
17
|
}
|
|
18
18
|
else if (z_re_inf == 0 && z_im_inf != 0)
|
|
19
19
|
{
|
|
20
|
+
const ID div = rb_intern("div");
|
|
20
21
|
VALUE real = BIG_INF;
|
|
21
|
-
VALUE imag =
|
|
22
|
+
VALUE imag = rb_funcall(rb_bigmath_const_pi(prec),
|
|
23
|
+
div, 2, INT2FIX(2), prec);
|
|
24
|
+
if (z_im_inf == -1)
|
|
25
|
+
imag = rb_num_uminus(imag);
|
|
22
26
|
return rb_Complex(real, imag);
|
|
23
27
|
}
|
|
24
|
-
else if (z_re_inf == -1 && z_im_inf == 1)
|
|
25
|
-
return rb_Complex(BIG_NAN, BIG_NAN);
|
|
26
28
|
else
|
|
27
|
-
return rb_Complex(
|
|
29
|
+
return rb_Complex(BIG_INF, BIG_NAN);
|
|
28
30
|
}
|
|
29
31
|
else
|
|
30
32
|
{
|
|
@@ -4,26 +4,30 @@ casec_branch(VALUE z, VALUE prec, bigmath_func1 casec_cb)
|
|
|
4
4
|
int z_re_inf = rb_num_infinite_p(rb_num_real(z));
|
|
5
5
|
int z_im_inf = rb_num_infinite_p(rb_num_imag(z));
|
|
6
6
|
|
|
7
|
+
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
|
8
|
+
|
|
7
9
|
if (rb_num_nan_p(z))
|
|
8
10
|
{
|
|
9
11
|
return rb_Complex(BIG_NAN, BIG_NAN);
|
|
10
12
|
}
|
|
11
13
|
else if (z_re_inf || z_im_inf)
|
|
12
14
|
{
|
|
13
|
-
|
|
15
|
+
const ID div = rb_intern("div");
|
|
16
|
+
VALUE real = rb_bigmath_const_pi(prec);
|
|
17
|
+
real = rb_funcall(real, div, 2, INT2FIX(2), prec);
|
|
18
|
+
return rb_Complex(real, BIG_ZERO);
|
|
14
19
|
}
|
|
15
20
|
else if (rb_num_zero_p(z))
|
|
16
21
|
{
|
|
17
22
|
int zero_sign = NUM2INT(rb_BigDecimal_sign(rb_num_real(z)));
|
|
18
23
|
VALUE real =
|
|
19
|
-
(rb_num_nonzero_p(rb_num_imag(z)) || zero_sign ==
|
|
24
|
+
(rb_num_nonzero_p(rb_num_imag(z)) || zero_sign == 1) ?
|
|
20
25
|
BIG_ZERO : rb_bigmath_const_pi(prec);
|
|
21
|
-
VALUE imag = 1 == zero_sign ? BIG_MINUS_INF : BIG_INF;
|
|
26
|
+
VALUE imag = -1 == zero_sign ? BIG_MINUS_INF : BIG_INF;
|
|
22
27
|
return rb_Complex(real, imag);
|
|
23
28
|
}
|
|
24
29
|
else
|
|
25
30
|
{
|
|
26
|
-
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
|
27
31
|
return casec_cb(z, prec);
|
|
28
32
|
}
|
|
29
33
|
}
|
|
@@ -10,20 +10,13 @@ casech_branch(VALUE z, VALUE prec, bigmath_func1 casech_cb)
|
|
|
10
10
|
else if (z_re_inf || z_im_inf)
|
|
11
11
|
{
|
|
12
12
|
const ID div = rb_intern("div");
|
|
13
|
-
if (z_re_inf != 0 && z_im_inf == 0)
|
|
13
|
+
if ((z_re_inf != 0 && z_im_inf == 0) ||
|
|
14
|
+
(z_re_inf == 0 && z_im_inf != 0))
|
|
14
15
|
{
|
|
15
16
|
VALUE imag = rb_funcall(rb_bigmath_const_pi(prec), div,
|
|
16
17
|
2, INT2FIX(2), prec);
|
|
17
18
|
w = rb_Complex(BIG_ZERO, imag);
|
|
18
19
|
}
|
|
19
|
-
else if (z_re_inf == 0 && z_im_inf != 0)
|
|
20
|
-
{
|
|
21
|
-
VALUE imag = rb_funcall(rb_bigmath_const_pi(prec), div,
|
|
22
|
-
2, INT2FIX(-2 * z_im_inf), prec);
|
|
23
|
-
w = rb_Complex(BIG_ZERO, imag);
|
|
24
|
-
}
|
|
25
|
-
else if (z_re_inf == -1 && z_im_inf == 1)
|
|
26
|
-
w = rb_Complex(BIG_NAN, BIG_NAN);
|
|
27
20
|
else
|
|
28
21
|
w = rb_Complex(BIG_ZERO, BIG_ZERO);
|
|
29
22
|
}
|
|
@@ -35,4 +28,3 @@ casech_branch(VALUE z, VALUE prec, bigmath_func1 casech_cb)
|
|
|
35
28
|
|
|
36
29
|
return w;
|
|
37
30
|
}
|
|
38
|
-
|
|
@@ -9,23 +9,38 @@ casin_branch(VALUE z, VALUE prec, bigmath_func1 casin_cb)
|
|
|
9
9
|
else if (z_re_inf || z_im_inf)
|
|
10
10
|
{
|
|
11
11
|
const ID div = rb_intern("div");
|
|
12
|
+
const ID mult = rb_intern("mult");
|
|
13
|
+
VALUE real, imag;
|
|
12
14
|
if (z_re_inf != 0 && z_im_inf == 0)
|
|
13
15
|
{
|
|
14
|
-
|
|
16
|
+
real =
|
|
15
17
|
rb_funcall(rb_bigmath_const_pi(prec), div, 2,
|
|
16
|
-
INT2FIX(z_re_inf * 2), prec)
|
|
17
|
-
|
|
18
|
-
VALUE imag = z_re_inf == 1 ? BIG_MINUS_INF : BIG_INF;
|
|
18
|
+
INT2FIX(z_re_inf * 2), prec);
|
|
19
|
+
imag = z_re_inf == 1 ? BIG_MINUS_INF : BIG_INF;
|
|
19
20
|
return rb_Complex(real, imag);
|
|
20
21
|
}
|
|
21
22
|
else if (z_re_inf == 0 && z_im_inf != 0)
|
|
22
23
|
{
|
|
23
|
-
|
|
24
|
+
real = rb_bigmath_const_pi(prec);
|
|
25
|
+
imag = BIG_MINUS_INF;
|
|
26
|
+
if (z_im_inf == -1)
|
|
27
|
+
real = rb_funcall(real, div, 2, INT2FIX(2), prec);
|
|
28
|
+
return rb_Complex(real, imag);
|
|
24
29
|
}
|
|
25
|
-
else if (z_re_inf == -1 && z_im_inf == 1)
|
|
26
|
-
return rb_Complex(BIG_NAN, BIG_NAN);
|
|
27
30
|
else
|
|
28
|
-
|
|
31
|
+
{
|
|
32
|
+
VALUE rat = Qundef;
|
|
33
|
+
real = rb_bigmath_const_pi(prec);
|
|
34
|
+
imag = BIG_MINUS_INF;
|
|
35
|
+
if (z_re_inf == 1 && z_im_inf == 1)
|
|
36
|
+
rat = rb_rational_new(INT2FIX(5), INT2FIX(4));
|
|
37
|
+
else if (z_re_inf == 1 && z_im_inf == -1)
|
|
38
|
+
rat = rb_rational_new(INT2FIX(3), INT2FIX(4));
|
|
39
|
+
else
|
|
40
|
+
rat = rb_rational_new(INT2FIX(1), INT2FIX(4));
|
|
41
|
+
real = rb_funcall(real, mult, 2, rat, prec);
|
|
42
|
+
return rb_Complex(real, imag);
|
|
43
|
+
}
|
|
29
44
|
}
|
|
30
45
|
else
|
|
31
46
|
{
|
|
@@ -3,13 +3,18 @@ casinh_branch(VALUE z, VALUE prec, bigmath_func1 casinh_cb)
|
|
|
3
3
|
{
|
|
4
4
|
VALUE y = Qundef;
|
|
5
5
|
|
|
6
|
+
int z_re_inf = rb_num_infinite_p(rb_num_real(z));
|
|
7
|
+
int z_im_inf = rb_num_infinite_p(rb_num_imag(z));
|
|
8
|
+
|
|
6
9
|
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
|
7
10
|
|
|
8
|
-
if (
|
|
11
|
+
if (rb_num_nan_p(z))
|
|
12
|
+
y = rb_Complex(BIG_NAN, BIG_NAN);
|
|
13
|
+
else if (!rb_num_finite_p(z))
|
|
9
14
|
{
|
|
10
|
-
if (
|
|
15
|
+
if (z_re_inf != 0 && z_im_inf == 0)
|
|
11
16
|
{
|
|
12
|
-
switch (
|
|
17
|
+
switch (z_re_inf) {
|
|
13
18
|
case 1:
|
|
14
19
|
y = rb_Complex(BIG_INF, BIG_ZERO);
|
|
15
20
|
break;
|
|
@@ -18,37 +23,27 @@ casinh_branch(VALUE z, VALUE prec, bigmath_func1 casinh_cb)
|
|
|
18
23
|
break;
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
|
-
else if (
|
|
26
|
+
else if (z_re_inf == 0 && z_im_inf != 0)
|
|
22
27
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
else
|
|
35
|
-
{
|
|
36
|
-
const ID div = rb_intern("div");
|
|
37
|
-
VALUE pi_2 = rb_funcall(rb_bigmath_const_pi(prec), div, 2, INT2FIX(2), prec);
|
|
38
|
-
switch (rb_num_infinite_p(rb_num_imag(z))) {
|
|
39
|
-
case 1:
|
|
40
|
-
y = rb_Complex(BIG_INF, pi_2);
|
|
41
|
-
break;
|
|
42
|
-
case -1:
|
|
43
|
-
pi_2 = rb_num_uminus(pi_2);
|
|
44
|
-
y = rb_Complex(BIG_ZERO, pi_2);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
28
|
+
const ID div = rb_intern("div");
|
|
29
|
+
VALUE pi_2 = rb_funcall(rb_bigmath_const_pi(prec), div, 2, INT2FIX(2), prec);
|
|
30
|
+
switch (z_im_inf) {
|
|
31
|
+
case 1:
|
|
32
|
+
y = rb_Complex(BIG_INF, pi_2);
|
|
33
|
+
break;
|
|
34
|
+
case -1:
|
|
35
|
+
pi_2 = rb_num_uminus(pi_2);
|
|
36
|
+
y = rb_Complex(BIG_INF, pi_2);
|
|
37
|
+
break;
|
|
47
38
|
}
|
|
48
39
|
}
|
|
49
40
|
else
|
|
50
41
|
{
|
|
51
|
-
|
|
42
|
+
VALUE real = BIG_INF;
|
|
43
|
+
VALUE imag = BIG_NAN;
|
|
44
|
+
if (z_re_inf == -1)
|
|
45
|
+
real = rb_num_uminus(real);
|
|
46
|
+
y = rb_Complex(real, imag);
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
49
|
if (y == Qundef)
|
|
@@ -10,27 +10,30 @@ catan_branch(VALUE z, VALUE prec, bigmath_func1 catan_cb)
|
|
|
10
10
|
return rb_Complex(BIG_NAN, BIG_NAN);
|
|
11
11
|
else if (z_re_inf || z_im_inf)
|
|
12
12
|
{
|
|
13
|
+
const ID mult = rb_intern("mult");
|
|
13
14
|
const ID div = rb_intern("div");
|
|
15
|
+
VALUE real, imag;
|
|
14
16
|
if (z_re_inf != 0 && z_im_inf == 0)
|
|
15
17
|
{
|
|
16
|
-
|
|
17
|
-
rb_funcall(rb_bigmath_const_pi(prec), div, 2,
|
|
18
|
+
real = rb_funcall(rb_bigmath_const_pi(prec), div, 2,
|
|
18
19
|
INT2FIX(z_re_inf * 2), prec);
|
|
19
|
-
|
|
20
|
+
imag = BIG_ZERO;
|
|
20
21
|
return rb_Complex(real, imag);
|
|
21
22
|
}
|
|
22
23
|
else if (z_re_inf == 0 && z_im_inf != 0)
|
|
23
24
|
{
|
|
24
|
-
|
|
25
|
-
rb_funcall(rb_bigmath_const_pi(prec), div, 2,
|
|
25
|
+
real = rb_funcall(rb_bigmath_const_pi(prec), div, 2,
|
|
26
26
|
INT2FIX(z_im_inf * 2), prec);
|
|
27
|
-
|
|
27
|
+
imag = BIG_ZERO;
|
|
28
28
|
return rb_Complex(real, imag);
|
|
29
29
|
}
|
|
30
|
-
else if (z_re_inf == -1 && z_im_inf == 1)
|
|
31
|
-
return rb_Complex(BIG_NAN, BIG_NAN);
|
|
32
30
|
else
|
|
33
|
-
|
|
31
|
+
{
|
|
32
|
+
real = rb_funcall(rb_bigmath_const_pi(prec), mult, 2,
|
|
33
|
+
rb_rational_new(INT2FIX(z_im_inf * 3), INT2FIX(4)), prec);
|
|
34
|
+
imag = BIG_ZERO;
|
|
35
|
+
return rb_Complex(real, imag);
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
else if (rb_num_equal_p(z, rb_Complex_I))
|
|
36
39
|
return rb_Complex(BIG_ZERO, BIG_INF);
|
|
@@ -2,19 +2,26 @@ VALUE
|
|
|
2
2
|
catanh_branch(VALUE z, VALUE prec, bigmath_func1 catanh_cb)
|
|
3
3
|
{
|
|
4
4
|
VALUE w = Qundef;
|
|
5
|
+
int z_re_inf = rb_num_infinite_p(rb_num_real(z));
|
|
6
|
+
int z_im_inf = rb_num_infinite_p(rb_num_imag(z));
|
|
5
7
|
|
|
6
8
|
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
|
7
9
|
|
|
8
10
|
if (rb_num_nan_p(z))
|
|
9
11
|
w = rb_Complex(BIG_NAN, BIG_NAN);
|
|
10
|
-
else if (
|
|
12
|
+
else if (z_re_inf || z_im_inf)
|
|
11
13
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (z_re_inf != 0 && z_im_inf != 0)
|
|
15
|
+
w = rb_Complex(BIG_NAN, BIG_NAN);
|
|
16
|
+
else
|
|
17
|
+
{
|
|
18
|
+
const ID div = rb_intern("div");
|
|
19
|
+
VALUE pi_2 = rb_funcall(
|
|
20
|
+
rb_bigmath_const_pi(prec), div, 2, INT2FIX(2), prec);
|
|
21
|
+
if (z_re_inf == 1 || z_im_inf == -1)
|
|
22
|
+
pi_2 = rb_num_uminus(pi_2);
|
|
23
|
+
w = rb_Complex(BIG_ZERO, pi_2);
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
else
|
|
20
27
|
{
|
|
@@ -2,7 +2,9 @@ VALUE
|
|
|
2
2
|
ccosh_branch(VALUE z, VALUE prec, bigmath_func1 ccosh_cb)
|
|
3
3
|
{
|
|
4
4
|
VALUE w = Qundef;
|
|
5
|
-
if (
|
|
5
|
+
if (rb_num_nan_p(z))
|
|
6
|
+
w = rb_Complex(BIG_NAN, BIG_NAN);
|
|
7
|
+
else if (!rb_num_finite_p(z))
|
|
6
8
|
{
|
|
7
9
|
if (rb_num_infinite_p(z) != 0 && rb_num_zero_p(rb_num_imag(z)))
|
|
8
10
|
{
|
|
@@ -5,8 +5,12 @@ cpow_formula(VALUE z, VALUE w, VALUE prec)
|
|
|
5
5
|
|
|
6
6
|
rb_check_precise(prec);
|
|
7
7
|
n = rb_numdiff_make_n(prec);
|
|
8
|
-
|
|
9
|
-
if (
|
|
8
|
+
|
|
9
|
+
if (!rb_num_finite_p(z) || !rb_num_finite_p(w))
|
|
10
|
+
{
|
|
11
|
+
a = rb_Complex(BIG_NAN, BIG_NAN);
|
|
12
|
+
}
|
|
13
|
+
else if (rb_num_positive_p(rb_num_real(z)) &&
|
|
10
14
|
rb_num_zero_p(rb_num_imag(z)) && rb_num_zero_p(rb_num_imag(w)))
|
|
11
15
|
{
|
|
12
16
|
a = pow_formula(rb_num_real(z), rb_num_real(w), n);
|
|
@@ -19,7 +19,7 @@ rcm2_edf(VALUE x, VALUE *reso)
|
|
|
19
19
|
while (RTEST(rb_num_coerce_cmp(INT2FIX(2), fra, rb_intern("<="))))
|
|
20
20
|
{
|
|
21
21
|
fra = rb_funcall1(fra, '/', rat_two);
|
|
22
|
-
TYPE(resov) == T_FIXNUM ?
|
|
22
|
+
resov = TYPE(resov) == T_FIXNUM ?
|
|
23
23
|
LONG2FIX(FIX2LONG(resov) + 1) :
|
|
24
24
|
rb_funcall(resov, succ, 0);
|
|
25
25
|
}
|
|
@@ -29,7 +29,7 @@ rcm2_edf(VALUE x, VALUE *reso)
|
|
|
29
29
|
while (RTEST(rb_num_coerce_cmp(INT2FIX(1), fra, '>')))
|
|
30
30
|
{
|
|
31
31
|
fra = rb_funcall1(fra, '*', rat_two);
|
|
32
|
-
TYPE(resov) == T_FIXNUM ?
|
|
32
|
+
resov = TYPE(resov) == T_FIXNUM ?
|
|
33
33
|
LONG2FIX(FIX2LONG(resov) - 1) :
|
|
34
34
|
rb_funcall(resov, pred, 0);
|
|
35
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Make euler's formula, e^i(theta) as *exppz and e^-i(theta) as *expmz
|
|
1
2
|
static inline void
|
|
2
3
|
f_euler2(VALUE theta, VALUE prec, VALUE *exppz, VALUE *expmz)
|
|
3
4
|
{
|
|
@@ -6,7 +7,7 @@ f_euler2(VALUE theta, VALUE prec, VALUE *exppz, VALUE *expmz)
|
|
|
6
7
|
*expmz = rb_funcall(*exppz, conj, 0);
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
// Make euler's formula of complex exponent, e^(theta) as *exppz and e^-(theta) as *expmz
|
|
10
11
|
static inline void
|
|
11
12
|
f_euler_e2(VALUE theta, VALUE prec, VALUE *exppz, VALUE *expmz)
|
|
12
13
|
{
|
|
@@ -33,7 +34,7 @@ f_euler_e2(VALUE theta, VALUE prec, VALUE *exppz, VALUE *expmz)
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
// Euler's formula for cos()
|
|
37
38
|
static inline VALUE
|
|
38
39
|
f_euler_cos(VALUE exppz, VALUE expmz)
|
|
39
40
|
{
|
|
@@ -44,6 +45,7 @@ f_euler_cos(VALUE exppz, VALUE expmz)
|
|
|
44
45
|
return y;
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
// Euler's formula for sin(), when argument is infinite
|
|
47
49
|
static inline VALUE
|
|
48
50
|
f_euler_sin_infinite(VALUE y)
|
|
49
51
|
{
|
|
@@ -97,6 +99,7 @@ f_euler_sin_infinite(VALUE y)
|
|
|
97
99
|
return w;
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
// Euler's formula for sin()
|
|
100
103
|
static inline VALUE
|
|
101
104
|
f_euler_sin(VALUE exppz, VALUE expmz)
|
|
102
105
|
{
|
|
@@ -112,6 +115,7 @@ f_euler_sin(VALUE exppz, VALUE expmz)
|
|
|
112
115
|
return y;
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
// Euler's formula for tan()
|
|
115
119
|
static inline VALUE
|
|
116
120
|
f_euler_tan(VALUE exppz, VALUE expmz)
|
|
117
121
|
{
|
|
@@ -128,6 +132,7 @@ f_euler_tan(VALUE exppz, VALUE expmz)
|
|
|
128
132
|
return rb_funcall1(sin, '/', cos);
|
|
129
133
|
}
|
|
130
134
|
|
|
135
|
+
// Euler's formula for sin and cos
|
|
131
136
|
static inline VALUE
|
|
132
137
|
f_euler_sc(const ID func, VALUE theta, VALUE prec)
|
|
133
138
|
{
|
|
@@ -208,7 +213,7 @@ f_euler_t(VALUE theta, VALUE prec)
|
|
|
208
213
|
return rb_ImaginaryZ(y, SIGN_MINUS);
|
|
209
214
|
}
|
|
210
215
|
|
|
211
|
-
|
|
216
|
+
// For hyperbolic
|
|
212
217
|
static inline VALUE
|
|
213
218
|
f_euler_h(const ID func, VALUE theta, VALUE prec)
|
|
214
219
|
{
|
|
@@ -230,6 +235,7 @@ f_euler_h(const ID func, VALUE theta, VALUE prec)
|
|
|
230
235
|
return rb_num_round(y, prec);
|
|
231
236
|
}
|
|
232
237
|
|
|
238
|
+
// Mix Euler's formula of exponent and sincos
|
|
233
239
|
static inline VALUE
|
|
234
240
|
f_euler_esc(const ID func, VALUE z, VALUE prec)
|
|
235
241
|
{
|