bigdecimal-math_r 0.2.0 → 0.2.1
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 +63 -10
- data/changelog.md +18 -0
- data/ext/bigdecimal/math_r/api/numeric/domain_p.h +7 -0
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acos/branch.h +11 -4
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acosh/branch.h +2 -2
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acoth/branch.h +4 -4
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsc/branch.h +3 -4
- data/ext/bigdecimal/math_r/internal/algo/bigmath/acsch/branch.h +3 -9
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asec/branch.h +7 -4
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asech/branch.h +2 -5
- data/ext/bigdecimal/math_r/internal/algo/bigmath/asin/branch.h +4 -2
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/branch.h +1 -1
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_euler.h +2 -50
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atan/ser_usual.h +2 -9
- data/ext/bigdecimal/math_r/internal/algo/bigmath/atanh/branch.h +4 -3
- data/ext/bigdecimal/math_r/internal/algo/bigmath/cpow/formula.h +2 -1
- data/ext/bigdecimal/math_r/internal/algo/bigmath/sqrt/branch.h +2 -1
- data/ext/bigdecimal/math_r/log.c +3 -3
- data/ext/bigdecimal/math_r/math_r/numeric.h +1 -0
- data/ext/bigdecimal/math_r/math_r.c +9 -0
- data/ext/bigdecimal/math_r/solver.c +75 -21
- data/lib/bigdecimal/math_r/version.rb +1 -1
- data/lib/bigdecimal/math_r.so +0 -0
- metadata +2 -2
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719ac1d5b1b20031ea157c824a660307e45adf15bf00edd6f906eaef31e8ef47
|
4
|
+
data.tar.gz: 4340bfae2018a9c332991f5c5e0ab4833f0ad914a15a05729ae68e07833a25fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eb916c9ab6c4f2288c7b8a5c9d36dfe5879bf547082fba2be2e4ea01925e97fd5de4f7445d0d28dee03faa457502d8a86107ac71d5c417d1508cf8a2e4a44dd
|
7
|
+
data.tar.gz: 2fcc65443645680121c138272d4825d9707fa9296936b114ab2e630f49213f0710ada866c3c080bc9c38a332a7e9f5cdefb24bac2e0c528efec910cbc35cb6ef
|
data/README.md
CHANGED
@@ -4,23 +4,76 @@ This is a math module that using the BigDecimal class. Multiple-precision arithm
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Install the gem and add to the application's Gemfile by executing:
|
7
|
+
It doesn't use any external libraries that have dependencies. Use only the BigDecimal class.
|
10
8
|
|
11
9
|
```bash
|
12
|
-
|
10
|
+
gem install bigdecimal-math_r
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
## Usage
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
When it is called, the BigDecimal class is also called.
|
16
|
+
|
17
|
+
```Ruby
|
18
|
+
require 'bigdecimal/math_r'
|
19
19
|
```
|
20
20
|
|
21
|
-
|
21
|
+
The functions at the top level `BigMathR` of the module, are mathematical constants in uppercase letters, and mathematical functions in lowercase.
|
22
|
+
Mathematical functions are compatible with both real and complex solutions.
|
22
23
|
|
23
|
-
|
24
|
+
Constants:
|
25
|
+
```
|
26
|
+
:E (Constant e),
|
27
|
+
:LOG2 (Natural logarithm of 2)
|
28
|
+
:LOG_PI (Natural logarithm of pi)
|
29
|
+
:LOG10 (Natural logarithm of 10)
|
30
|
+
:SQRT2 (Square root of 2)
|
31
|
+
:SQRT3 (Square root of 3)
|
32
|
+
:PI (Constant pi)
|
33
|
+
```
|
34
|
+
Functions:
|
35
|
+
```
|
36
|
+
:exp (Exponential function)
|
37
|
+
:exp2 (Base-2 (Binary) exponent)
|
38
|
+
|
39
|
+
:log (Natural logarithm)
|
40
|
+
:log2 (Binary logarithm)
|
41
|
+
:log10 (Common logarithm)
|
42
|
+
:log1p (log(1+x))
|
43
|
+
|
44
|
+
:hypot (Hypotenuse)
|
45
|
+
|
46
|
+
:sqrt (Square root)
|
47
|
+
:cbrt (Cubic root)
|
48
|
+
|
49
|
+
:sin (Sine)
|
50
|
+
:cos (Cosine)
|
51
|
+
:tan (Tangent)
|
52
|
+
:sec (Secant)
|
53
|
+
:csc (Cosecant)
|
54
|
+
:cot (Cotangent)
|
55
|
+
|
56
|
+
:sinh (Hyperbolic sine)
|
57
|
+
:cosh (Hyperbolic cosine)
|
58
|
+
:tanh (Hyperbolic tangent)
|
59
|
+
:csch (Hyperbolic cosecant)
|
60
|
+
:sech (Hyperbolic secant)
|
61
|
+
:coth (Hyperbolic cotangent)
|
62
|
+
|
63
|
+
:asin (Inverse Sine)
|
64
|
+
:acos (Inverse Cosine)
|
65
|
+
:atan, :atan2 (Inverse Tangent)
|
66
|
+
:acsc (Inverse Cosecant)
|
67
|
+
:asec (Inverse Secant)
|
68
|
+
:acot (Inverse Cotangent)
|
69
|
+
|
70
|
+
:acosh (Inverse Hyperbolic Sine)
|
71
|
+
:asinh (Inverse Hyperbolic Cosine)
|
72
|
+
:atanh (Inverse Hyperbolic Tangent)
|
73
|
+
:acsch (Inverse Hyperbolic Cosecant)
|
74
|
+
:asech (Inverse Hyperbolic Secant)
|
75
|
+
:acoth (Inverse Hyperbolic Cotangent)
|
76
|
+
```
|
24
77
|
|
25
78
|
## Development
|
26
79
|
|
@@ -30,7 +83,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
30
83
|
|
31
84
|
## Contributing
|
32
85
|
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tribusonz-2/bigdecimal-math_r. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tribusonz-2/bigdecimal-math_r/blob/main/CODE_OF_CONDUCT.md).
|
34
87
|
|
35
88
|
## License
|
36
89
|
|
data/changelog.md
CHANGED
@@ -7,6 +7,24 @@ 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.1] - 2025-05-XX
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- `atan_branch()` limit a calculation range in $0 \lt x \lt \frac{1}{2}$ .
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- `cpow_formula()` return complex solution when left hand side is in negative real number.
|
17
|
+
- `acsch_branch()` had a domain.
|
18
|
+
- `sqrt_branch()` API did not perform an implicit type conversion.
|
19
|
+
- The global constant was set when the library was loaded.
|
20
|
+
- `log*_edf()` was not defined in the sub-module `Log`.
|
21
|
+
|
22
|
+
### Added
|
23
|
+
- Add API `rb_num_domain_p()`. This query whether an argument is in the domain.
|
24
|
+
- Add minitest.
|
25
|
+
|
26
|
+
## [0.2.0] - 2025-05-XX
|
27
|
+
|
10
28
|
### Changed
|
11
29
|
- Rename `BigMathR::PowerRoot` to `BigMathR::Power`
|
12
30
|
|
@@ -2,21 +2,28 @@ VALUE
|
|
2
2
|
acos_branch(VALUE x, VALUE prec, bigmath_func1 acos_cb)
|
3
3
|
{
|
4
4
|
const ID leq = rb_intern("<=");
|
5
|
-
VALUE y = Qundef
|
5
|
+
VALUE y = Qundef;
|
6
|
+
VALUE p001 = rb_BigDecimal1(rb_str_new_cstr("0.001"));
|
7
|
+
VALUE domain = rb_range_new(INT2FIX(0), INT2FIX(1), true);
|
8
|
+
|
6
9
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
7
10
|
|
8
11
|
if (!rb_num_finite_p(x))
|
9
12
|
y = x;
|
10
13
|
else
|
11
14
|
{
|
12
|
-
VALUE absx =
|
15
|
+
VALUE absx = rb_num_abs(x);
|
13
16
|
if (RTEST(rb_num_coerce_cmp(absx, p001, leq)))
|
14
17
|
{
|
15
18
|
y = acos_ser(x, prec);
|
16
19
|
}
|
17
|
-
else if (
|
20
|
+
else if (rb_num_domain_p(domain, absx))
|
18
21
|
{
|
19
|
-
|
22
|
+
if (rb_num_equal_p(absx, INT2FIX(1)))
|
23
|
+
y = rb_num_negative_p(x) ?
|
24
|
+
rb_bigmath_const_pi(prec) : BIG_ZERO;
|
25
|
+
else
|
26
|
+
y = acos_cb(x, prec);
|
20
27
|
}
|
21
28
|
else
|
22
29
|
y = BIG_NAN;
|
@@ -1,15 +1,15 @@
|
|
1
1
|
VALUE
|
2
2
|
acosh_branch(VALUE x, VALUE prec, bigmath_func1 acosh_cb)
|
3
3
|
{
|
4
|
-
const ID geq = rb_intern(">=");
|
5
4
|
VALUE y = Qundef;
|
5
|
+
VALUE domain = rb_range_new(INT2FIX(1), DBL2NUM(HUGE_VAL), false);
|
6
6
|
|
7
7
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
8
8
|
if (rb_num_positive_p(x))
|
9
9
|
{
|
10
10
|
if (rb_num_infinite_p(x) == 1)
|
11
11
|
y = BIG_INF;
|
12
|
-
else if (
|
12
|
+
else if (rb_num_domain_p(domain, x))
|
13
13
|
y = acosh_cb(x, prec);
|
14
14
|
}
|
15
15
|
if (y == Qundef)
|
@@ -1,8 +1,9 @@
|
|
1
1
|
VALUE
|
2
2
|
acoth_branch(VALUE x, VALUE prec, bigmath_func1 acoth_cb)
|
3
3
|
{
|
4
|
-
VALUE y;
|
5
|
-
|
4
|
+
VALUE y = Qundef;
|
5
|
+
VALUE p_domain = rb_range_new(INT2FIX(1), DBL2NUM(HUGE_VAL), false);
|
6
|
+
VALUE m_domain = rb_range_new(DBL2NUM(-HUGE_VAL), INT2FIX(-1), true);
|
6
7
|
|
7
8
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
8
9
|
|
@@ -10,8 +11,7 @@ acoth_branch(VALUE x, VALUE prec, bigmath_func1 acoth_cb)
|
|
10
11
|
y = BIG_INF;
|
11
12
|
else if (rb_num_equal_p(x, BIG_MINUS_ONE))
|
12
13
|
y = BIG_MINUS_INF;
|
13
|
-
else if (
|
14
|
-
RTEST(rb_num_coerce_cmp(BIG_ONE, x, leq)))
|
14
|
+
else if (rb_num_domain_p(p_domain, x) || rb_num_domain_p(m_domain, x))
|
15
15
|
y = acoth_cb(x, prec);
|
16
16
|
else
|
17
17
|
y = BIG_NAN;
|
@@ -1,9 +1,9 @@
|
|
1
1
|
VALUE
|
2
2
|
acsc_branch(VALUE x, VALUE prec, bigmath_func1 acsc_cb)
|
3
3
|
{
|
4
|
-
const ID leq = rb_intern("<=");
|
5
|
-
const ID geq = rb_intern(">=");
|
6
4
|
VALUE y = Qundef;
|
5
|
+
VALUE p_domain = rb_range_new(INT2FIX(1), DBL2NUM(HUGE_VAL), false);
|
6
|
+
VALUE m_domain = rb_range_new(DBL2NUM(-HUGE_VAL), INT2FIX(-1), true);
|
7
7
|
|
8
8
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
9
9
|
|
@@ -11,8 +11,7 @@ acsc_branch(VALUE x, VALUE prec, bigmath_func1 acsc_cb)
|
|
11
11
|
y = BIG_NAN;
|
12
12
|
else if (rb_num_infinite_p(x) != 0)
|
13
13
|
y = BIG_ONE;
|
14
|
-
else if (
|
15
|
-
RTEST(rb_num_coerce_bin(x, INT2FIX( 1), geq)))
|
14
|
+
else if (rb_num_domain_p(p_domain, x) || rb_num_domain_p(m_domain, x))
|
16
15
|
y = acsc_cb(x, prec);
|
17
16
|
else
|
18
17
|
y = BIG_NAN;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
VALUE
|
2
2
|
acsch_branch(VALUE x, VALUE prec, bigmath_func1 acsch_cb)
|
3
3
|
{
|
4
|
-
const ID leq = rb_intern("<=");
|
5
4
|
VALUE y = Qundef;
|
6
5
|
int sign;
|
7
6
|
|
@@ -10,16 +9,11 @@ acsch_branch(VALUE x, VALUE prec, bigmath_func1 acsch_cb)
|
|
10
9
|
if (rb_num_nan_p(x))
|
11
10
|
y = BIG_NAN;
|
12
11
|
else if ((sign = rb_num_infinite_p(x)) != 0)
|
13
|
-
{
|
14
12
|
y = sign == 1 ? BIG_ZERO : BIG_MINUS_ZERO;
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
{
|
13
|
+
else if (rb_num_zero_p(x))
|
14
|
+
y = BIG_INF;
|
15
|
+
else
|
19
16
|
y = acsch_cb(x, prec);
|
20
|
-
}
|
21
|
-
else
|
22
|
-
y = BIG_NAN;
|
23
17
|
|
24
18
|
return y;
|
25
19
|
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
VALUE
|
2
2
|
asec_branch(VALUE x, VALUE prec, bigmath_func1 asec_cb)
|
3
3
|
{
|
4
|
-
const ID leq = rb_intern("<=");
|
5
|
-
const ID geq = rb_intern(">=");
|
6
4
|
const ID div = rb_intern("div");
|
7
5
|
VALUE y = Qundef;
|
6
|
+
VALUE p_domain = rb_range_new(INT2FIX(1), DBL2NUM(HUGE_VAL), false);
|
7
|
+
VALUE m_domain = rb_range_new(DBL2NUM(-HUGE_VAL), INT2FIX(-1), true);
|
8
8
|
|
9
9
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
10
10
|
|
@@ -12,8 +12,11 @@ asec_branch(VALUE x, VALUE prec, bigmath_func1 asec_cb)
|
|
12
12
|
y = BIG_NAN;
|
13
13
|
else if (rb_num_infinite_p(x) != 0)
|
14
14
|
y = rb_funcall(rb_bigmath_const_pi(prec), div, 2, INT2FIX(2), prec);
|
15
|
-
else if (
|
16
|
-
|
15
|
+
else if (rb_num_equal_p(x, INT2FIX(-1)))
|
16
|
+
y = rb_bigmath_const_pi(prec);
|
17
|
+
else if (rb_num_equal_p(x, INT2FIX(0)))
|
18
|
+
y = BIG_ZERO;
|
19
|
+
else if (rb_num_domain_p(p_domain, x) || rb_num_domain_p(m_domain, x))
|
17
20
|
y = asec_cb(x, prec);
|
18
21
|
else
|
19
22
|
y = BIG_NAN;
|
@@ -1,16 +1,13 @@
|
|
1
1
|
VALUE
|
2
2
|
asech_branch(VALUE x, VALUE prec, bigmath_func1 asech_cb)
|
3
3
|
{
|
4
|
-
const ID leq = rb_intern("<=");
|
5
4
|
VALUE y;
|
5
|
+
VALUE domain = rb_range_new(INT2FIX(0), INT2FIX(1), true);
|
6
6
|
|
7
7
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
8
8
|
|
9
|
-
if (
|
10
|
-
RTEST(rb_num_coerce_cmp(x, BIG_ONE, leq)))
|
11
|
-
{
|
9
|
+
if (rb_num_domain_p(domain, x))
|
12
10
|
y = asech_cb(x, prec);
|
13
|
-
}
|
14
11
|
else
|
15
12
|
y = BIG_NAN;
|
16
13
|
|
@@ -2,7 +2,9 @@ VALUE
|
|
2
2
|
asin_branch(VALUE x, VALUE prec, bigmath_func1 asin_cb)
|
3
3
|
{
|
4
4
|
const ID leq = rb_intern("<=");
|
5
|
-
VALUE y = Qundef
|
5
|
+
VALUE y = Qundef;
|
6
|
+
VALUE p001 = rb_BigDecimal1(rb_str_new_cstr("0.001"));
|
7
|
+
VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), true);
|
6
8
|
|
7
9
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
8
10
|
|
@@ -13,7 +15,7 @@ asin_branch(VALUE x, VALUE prec, bigmath_func1 asin_cb)
|
|
13
15
|
VALUE absx = rb_num_negative_p(x) ? rb_num_uminus(x) : x;
|
14
16
|
if (RTEST(rb_num_coerce_cmp(absx, p001, leq)))
|
15
17
|
y = asin_ser(x, prec);
|
16
|
-
else if (
|
18
|
+
else if (rb_num_domain_p(domain, x))
|
17
19
|
y = asin_cb(x, prec);
|
18
20
|
else
|
19
21
|
y = BIG_NAN;
|
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
atan_ser_euler_inline(VALUE x, VALUE prec)
|
1
|
+
VALUE
|
2
|
+
atan_ser_euler(VALUE x, VALUE prec)
|
4
3
|
{
|
5
4
|
const ID add = rb_intern("add");
|
6
5
|
const ID mult = rb_intern("mult");
|
@@ -35,50 +34,3 @@ atan_ser_euler_inline(VALUE x, VALUE prec)
|
|
35
34
|
};
|
36
35
|
return rb_funcall(rb_funcall(y, div, 2, x, prec), mult, 2, s, prec);
|
37
36
|
}
|
38
|
-
#else
|
39
|
-
static VALUE
|
40
|
-
atan_ser_euler_inline(VALUE x, VALUE prec)
|
41
|
-
{
|
42
|
-
const ID add = rb_intern("add");
|
43
|
-
const ID mult = rb_intern("mult");
|
44
|
-
const ID div = rb_intern("div");
|
45
|
-
VALUE n, m, wt, w, r, y, d;
|
46
|
-
|
47
|
-
if (rb_num_zero_p(x))
|
48
|
-
return BIG_ZERO;
|
49
|
-
|
50
|
-
n = rb_numdiff_make_n(prec);
|
51
|
-
|
52
|
-
wt = rb_funcall(
|
53
|
-
rb_funcall(x, mult, 2, x, n), div, 2,
|
54
|
-
rb_funcall(BIG_ONE, add, 2, rb_funcall(x, mult, 2, x, n),
|
55
|
-
n), n);
|
56
|
-
w = BIG_ONE;
|
57
|
-
r = BIG_ONE;
|
58
|
-
y = BIG_ZERO;
|
59
|
-
d = BIG_ONE;
|
60
|
-
|
61
|
-
while (rb_numdiff_condition_p(y, d, n, &m))
|
62
|
-
{
|
63
|
-
d = rb_funcall(r, mult, 2, w, m);
|
64
|
-
y = rb_funcall1(y, '+', d);
|
65
|
-
r = rb_funcall1(r, '*', LONG2NUM(++n));
|
66
|
-
r = rb_funcall1(r, '/', LONG2NUM(++n));
|
67
|
-
w = rb_funcall1(w, '*', wt);
|
68
|
-
}
|
69
|
-
|
70
|
-
RB_GC_GUARD(wt);
|
71
|
-
RB_GC_GUARD(w);
|
72
|
-
RB_GC_GUARD(r);
|
73
|
-
RB_GC_GUARD(y);
|
74
|
-
RB_GC_GUARD(d);
|
75
|
-
|
76
|
-
return rb_funcall(rb_funcall(wt, div, 2, x, prec), mult, 2, y, prec);
|
77
|
-
}
|
78
|
-
#endif
|
79
|
-
|
80
|
-
VALUE
|
81
|
-
atan_ser_euler(VALUE x, VALUE prec)
|
82
|
-
{
|
83
|
-
return rb_bigmath_atan_adopt(x, prec, atan_ser_euler_inline);
|
84
|
-
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
VALUE
|
2
|
+
atan_ser_usual(VALUE x, VALUE prec)
|
3
3
|
{
|
4
4
|
const ID mult = rb_intern("mult");
|
5
5
|
const ID div = rb_intern("div");
|
@@ -32,10 +32,3 @@ atan_ser_usual_inline(VALUE x, VALUE prec)
|
|
32
32
|
|
33
33
|
return y;
|
34
34
|
}
|
35
|
-
|
36
|
-
|
37
|
-
VALUE
|
38
|
-
atan_ser_usual(VALUE x, VALUE prec)
|
39
|
-
{
|
40
|
-
return rb_bigmath_atan_adopt(x, prec, atan_ser_usual_inline);
|
41
|
-
}
|
@@ -2,12 +2,13 @@ VALUE
|
|
2
2
|
atanh_branch(VALUE x, VALUE prec, bigmath_func1 atanh_cb)
|
3
3
|
{
|
4
4
|
const ID leq = rb_intern("<=");
|
5
|
-
VALUE y = Qundef
|
5
|
+
VALUE y = Qundef;
|
6
|
+
VALUE p0999 = rb_BigDecimal1(rb_str_new_cstr("0.999"));
|
7
|
+
VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), true);
|
6
8
|
|
7
9
|
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
8
10
|
|
9
|
-
if (
|
10
|
-
RTEST(rb_num_coerce_cmp(x, INT2FIX(1), leq)))
|
11
|
+
if (rb_num_domain_p(domain, x))
|
11
12
|
{
|
12
13
|
VALUE absx = rb_num_negative_p(x) ? rb_num_uminus(x) : x;
|
13
14
|
if (rb_num_equal_p(absx, INT2FIX(1)))
|
@@ -5,7 +5,8 @@ cpow_formula(VALUE z, VALUE w, VALUE prec)
|
|
5
5
|
|
6
6
|
rb_check_precise(prec);
|
7
7
|
|
8
|
-
if (
|
8
|
+
if (rb_num_positive_p(rb_num_real(z)) &&
|
9
|
+
rb_num_zero_p(rb_num_imag(z)) && rb_num_zero_p(rb_num_imag(w)))
|
9
10
|
{
|
10
11
|
a = pow_formula(rb_num_real(z), rb_num_real(w), prec);
|
11
12
|
a = rb_num_canonicalize(a, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
@@ -2,7 +2,8 @@ VALUE
|
|
2
2
|
sqrt_branch(VALUE x, VALUE prec, bigmath_func1 sqrt_cb)
|
3
3
|
{
|
4
4
|
#define SWITCH_PRECISION_NUMBER 2253
|
5
|
-
|
5
|
+
x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
|
6
|
+
|
6
7
|
if (rb_num_negative_p(x))
|
7
8
|
return BIG_NAN;
|
8
9
|
else if (!rb_num_finite_p(x))
|
data/ext/bigdecimal/math_r/log.c
CHANGED
@@ -243,9 +243,9 @@ InitVM_Log(void)
|
|
243
243
|
rb_define_module_function(rb_mLog, "log_builtin", __impl_log_builtin, 2);
|
244
244
|
rb_define_module_function(rb_mLog, "log_ser_okumura", __impl_log_ser_okumura, 2);
|
245
245
|
|
246
|
-
rb_define_module_function(
|
247
|
-
rb_define_module_function(
|
248
|
-
rb_define_module_function(
|
246
|
+
rb_define_module_function(rb_mLog, "log_edf", __impl_log_edf, 2);
|
247
|
+
rb_define_module_function(rb_mLog, "log2_edf", __impl_log2_edf, 2);
|
248
|
+
rb_define_module_function(rb_mLog, "log10_edf", __impl_log10_edf, 2);
|
249
249
|
|
250
250
|
rb_define_module_function(rb_mLog, "log1p_ser_mercator", __impl_log1p_ser_mercator, 2);
|
251
251
|
rb_define_module_function(rb_mLog, "log1p_p_adic", __impl_log1p_p_adic, 2);
|
@@ -7,6 +7,7 @@
|
|
7
7
|
#include <ruby.h>
|
8
8
|
#define DEFINE_SYMBOL
|
9
9
|
#include "math_r/globals.h"
|
10
|
+
#include "math_r/bigmath.h"
|
10
11
|
|
11
12
|
void InitVM_Overrides(void);
|
12
13
|
void InitVM_Const(void);
|
@@ -35,6 +36,14 @@ void InitVM_Solver(void);
|
|
35
36
|
void
|
36
37
|
Init_math_r(void)
|
37
38
|
{
|
39
|
+
rb_gv_set(BIGMATH_PI, Qnil);
|
40
|
+
rb_gv_set(BIGMATH_E, Qnil);
|
41
|
+
rb_gv_set(BIGMATH_LOG2, Qnil);
|
42
|
+
rb_gv_set(BIGMATH_LOG10, Qnil);
|
43
|
+
rb_gv_set(BIGMATH_LOG_PI, Qnil);
|
44
|
+
rb_gv_set(BIGMATH_SQRT2, Qnil);
|
45
|
+
rb_gv_set(BIGMATH_SQRT3, Qnil);
|
46
|
+
|
38
47
|
mf_exp = rb_intern_const("exp");
|
39
48
|
mf_exp2 = rb_intern_const("exp2");
|
40
49
|
mf_expm1 = rb_intern_const("expm1");
|
@@ -74,15 +74,15 @@ bigmath_func1 cb_casech;
|
|
74
74
|
bigmath_func1 cb_acoth;
|
75
75
|
bigmath_func1 cb_cacoth;
|
76
76
|
|
77
|
+
bigmath_func1 cb_sqrt;
|
78
|
+
bigmath_func1 cb_csqrt;
|
79
|
+
bigmath_func1 cb_cbrt;
|
80
|
+
bigmath_func1 cb_ccbrt;
|
81
|
+
|
82
|
+
bigmath_func1 cb_erf;
|
83
|
+
bigmath_func1 cb_erfc;
|
77
84
|
|
78
85
|
|
79
|
-
static bool
|
80
|
-
domain_p(VALUE range, VALUE x)
|
81
|
-
{
|
82
|
-
const ID cover_p = rb_intern("cover?");
|
83
|
-
VALUE ans = rb_funcall(range, cover_p, 1, x);
|
84
|
-
return ans == Qtrue ? true : false;
|
85
|
-
}
|
86
86
|
|
87
87
|
static void
|
88
88
|
rb_id_includes(int n, const ID *funcs, ID func)
|
@@ -867,7 +867,7 @@ solver_triginv(ID func, VALUE z, VALUE prec)
|
|
867
867
|
if (func == mf_asin)
|
868
868
|
{
|
869
869
|
VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), 0);
|
870
|
-
if (
|
870
|
+
if (rb_num_domain_p(domain, z))
|
871
871
|
w = asin_branch(z, prec, cb_asin);
|
872
872
|
else
|
873
873
|
w = asin_edom(z, prec);
|
@@ -875,7 +875,7 @@ solver_triginv(ID func, VALUE z, VALUE prec)
|
|
875
875
|
else if (func == mf_acos)
|
876
876
|
{
|
877
877
|
VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), 0);
|
878
|
-
if (
|
878
|
+
if (rb_num_domain_p(domain, z))
|
879
879
|
w = acos_branch(z, prec, cb_acos);
|
880
880
|
else
|
881
881
|
w = acos_edom(z, prec);
|
@@ -886,7 +886,7 @@ solver_triginv(ID func, VALUE z, VALUE prec)
|
|
886
886
|
{
|
887
887
|
VALUE m_domain = rb_range_new(BIG_MINUS_INF, BIG_MINUS_ONE, 0);
|
888
888
|
VALUE p_domain = rb_range_new(BIG_ONE, BIG_INF, 0);
|
889
|
-
if (
|
889
|
+
if (rb_num_domain_p(m_domain, z) || rb_num_domain_p(p_domain, z))
|
890
890
|
w = acsc_branch(z, prec, cb_acsc);
|
891
891
|
else
|
892
892
|
w = acsc_edom(z, prec);
|
@@ -895,7 +895,7 @@ solver_triginv(ID func, VALUE z, VALUE prec)
|
|
895
895
|
{
|
896
896
|
VALUE m_domain = rb_range_new(BIG_MINUS_INF, BIG_MINUS_ONE, 0);
|
897
897
|
VALUE p_domain = rb_range_new(BIG_ONE, BIG_INF, 0);
|
898
|
-
if (
|
898
|
+
if (rb_num_domain_p(m_domain, z) || rb_num_domain_p(p_domain, z))
|
899
899
|
w = asec_branch(z, prec, cb_asec);
|
900
900
|
else
|
901
901
|
w = asec_edom(z, prec);
|
@@ -1121,9 +1121,9 @@ solver_hyperbinv(ID func, VALUE z, VALUE prec)
|
|
1121
1121
|
{
|
1122
1122
|
VALUE m_domain = rb_range_new(BIG_MINUS_INF, BIG_MINUS_ONE, 0);
|
1123
1123
|
VALUE p_domain = rb_range_new(BIG_ONE, BIG_INF, 0);
|
1124
|
-
if (
|
1124
|
+
if (rb_num_domain_p(p_domain, z))
|
1125
1125
|
w = acosh_branch(z, prec, cb_acosh);
|
1126
|
-
else if (
|
1126
|
+
else if (rb_num_domain_p(m_domain, z))
|
1127
1127
|
{
|
1128
1128
|
z = rb_num_abs(z);
|
1129
1129
|
w = acosh_branch(z, prec, cb_acosh);
|
@@ -1135,7 +1135,7 @@ solver_hyperbinv(ID func, VALUE z, VALUE prec)
|
|
1135
1135
|
else if (func == mf_atanh)
|
1136
1136
|
{
|
1137
1137
|
VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), 0);
|
1138
|
-
if (
|
1138
|
+
if (rb_num_domain_p(domain, z))
|
1139
1139
|
w = atanh_branch(z, prec, cb_atanh);
|
1140
1140
|
else
|
1141
1141
|
w = atanh_edom(z, prec);
|
@@ -1148,9 +1148,9 @@ solver_hyperbinv(ID func, VALUE z, VALUE prec)
|
|
1148
1148
|
{
|
1149
1149
|
VALUE m_domain = rb_range_new(BIG_MINUS_ONE, BIG_ZERO, 0);
|
1150
1150
|
VALUE p_domain = rb_range_new(BIG_ZERO, BIG_ONE, 0);
|
1151
|
-
if (
|
1151
|
+
if (rb_num_domain_p(p_domain, z))
|
1152
1152
|
w = asech_branch(z, prec, cb_asech);
|
1153
|
-
else if (
|
1153
|
+
else if (rb_num_domain_p(m_domain, z))
|
1154
1154
|
{
|
1155
1155
|
w = asech_branch(z, prec, cb_asech);
|
1156
1156
|
w = rb_Complex(w, rb_bigmath_const_pi(prec));
|
@@ -1162,7 +1162,7 @@ solver_hyperbinv(ID func, VALUE z, VALUE prec)
|
|
1162
1162
|
{
|
1163
1163
|
VALUE m_domain = rb_range_new(BIG_MINUS_INF, BIG_MINUS_ONE, 0);
|
1164
1164
|
VALUE p_domain = rb_range_new(BIG_ONE, BIG_INF, 0);
|
1165
|
-
if (
|
1165
|
+
if (rb_num_domain_p(m_domain, z) || rb_num_domain_p(p_domain, z))
|
1166
1166
|
w = acoth_branch(z, prec, cb_acoth);
|
1167
1167
|
else
|
1168
1168
|
w = acoth_edom(z, prec);
|
@@ -1337,12 +1337,12 @@ __impl_bigmath_sqrt(VALUE unused_obj, VALUE z, VALUE prec)
|
|
1337
1337
|
if (rb_num_negative_p(z))
|
1338
1338
|
w = sqrt_edom(z, prec);
|
1339
1339
|
else
|
1340
|
-
w =
|
1340
|
+
w = cb_sqrt(z, prec);
|
1341
1341
|
}
|
1342
1342
|
else
|
1343
1343
|
{
|
1344
1344
|
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
1345
|
-
w =
|
1345
|
+
w = cb_csqrt(z, prec);
|
1346
1346
|
}
|
1347
1347
|
return w;
|
1348
1348
|
}
|
@@ -1374,16 +1374,58 @@ __impl_bigmath_cbrt(VALUE unused_obj, VALUE z, VALUE prec)
|
|
1374
1374
|
if (rb_num_real_p(z))
|
1375
1375
|
{
|
1376
1376
|
z = rb_num_canonicalize(z, prec, ARG_REAL, ARG_RAWVALUE);
|
1377
|
-
w =
|
1377
|
+
w = cb_cbrt(z, prec);
|
1378
1378
|
}
|
1379
1379
|
else
|
1380
1380
|
{
|
1381
1381
|
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
|
1382
|
-
w =
|
1382
|
+
w = cb_ccbrt(z, prec);
|
1383
1383
|
}
|
1384
1384
|
return w;
|
1385
1385
|
}
|
1386
1386
|
|
1387
|
+
/**
|
1388
|
+
* Computes error function of +z+.
|
1389
|
+
*
|
1390
|
+
* @param z [Numeric] Numerical argument
|
1391
|
+
* @param prec [Integer] Arbitrary precision
|
1392
|
+
* @return [BigDecimal] Real solution
|
1393
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
1394
|
+
* @raise [TypeError] Occurs when +z+ is not a numeric class.
|
1395
|
+
* @since 0.2.1
|
1396
|
+
* @example
|
1397
|
+
* BigMathR.erf(5, 20)
|
1398
|
+
* #=> 0.99999999999846254021e0
|
1399
|
+
* BigMathR.erf(5, 40)
|
1400
|
+
* #=> 0.9999999999984625402055719651498116565146e0
|
1401
|
+
*/
|
1402
|
+
static VALUE
|
1403
|
+
__impl_bigmath_erf(VALUE unused_obj, VALUE z, VALUE prec)
|
1404
|
+
{
|
1405
|
+
return erf_branch(z, prec, cb_erf);
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
/**
|
1409
|
+
* Computes complementary error function of +z+.
|
1410
|
+
*
|
1411
|
+
* @param z [Numeric] Numerical argument
|
1412
|
+
* @param prec [Integer] Arbitrary precision
|
1413
|
+
* @return [BigDecimal] Real solution
|
1414
|
+
* @raise [ArgumentError] Occurs when +prec+ is not a positive integer.
|
1415
|
+
* @raise [TypeError] Occurs when +z+ is not a numeric class.
|
1416
|
+
* @since 0.2.1
|
1417
|
+
* @example
|
1418
|
+
* BigMathR.erfc(5, 20)
|
1419
|
+
* #=> 0.153745979e-11
|
1420
|
+
* BigMathR.erfc(5, 40)
|
1421
|
+
* #=> 0.15374597944280348501883434854e-11
|
1422
|
+
*/
|
1423
|
+
static VALUE
|
1424
|
+
__impl_bigmath_erfc(VALUE unused_obj, VALUE z, VALUE prec)
|
1425
|
+
{
|
1426
|
+
return erfc_branch(z, prec, cb_erfc);
|
1427
|
+
}
|
1428
|
+
|
1387
1429
|
/**
|
1388
1430
|
* Document-module: BigMathR::Solver
|
1389
1431
|
*
|
@@ -1463,6 +1505,15 @@ InitVM_Solver(void)
|
|
1463
1505
|
cb_casech = casech_logrep;
|
1464
1506
|
cb_cacoth = cacoth_logrep;
|
1465
1507
|
|
1508
|
+
cb_sqrt = sqrt_newton;
|
1509
|
+
cb_csqrt = csqrt_formula;
|
1510
|
+
cb_cbrt = cuberoot_newton;
|
1511
|
+
cb_ccbrt = ccbrt_formula;
|
1512
|
+
|
1513
|
+
cb_erf = erf_algo911;
|
1514
|
+
cb_erfc = erfc_algo911;
|
1515
|
+
|
1516
|
+
|
1466
1517
|
rb_define_singleton_method(rb_mSolver, "exp", __impl_solver_exp, 3);
|
1467
1518
|
|
1468
1519
|
rb_define_singleton_method(rb_mBigMathR, "exp", __impl_bigmath_exp, 2);
|
@@ -1513,4 +1564,7 @@ InitVM_Solver(void)
|
|
1513
1564
|
|
1514
1565
|
rb_define_singleton_method(rb_mBigMathR, "sqrt", __impl_bigmath_sqrt, 2);
|
1515
1566
|
rb_define_singleton_method(rb_mBigMathR, "cbrt", __impl_bigmath_cbrt, 2);
|
1567
|
+
|
1568
|
+
rb_define_singleton_method(rb_mBigMathR, "erf", __impl_bigmath_erf, 2);
|
1569
|
+
rb_define_singleton_method(rb_mBigMathR, "erfc", __impl_bigmath_erfc, 2);
|
1516
1570
|
}
|
data/lib/bigdecimal/math_r.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigdecimal-math_r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tribusonz-2
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- ".ruby-version"
|
63
63
|
- CODE_OF_CONDUCT.md
|
64
64
|
- LICENSE
|
65
|
-
- LICENSE.txt
|
66
65
|
- README.md
|
67
66
|
- Rakefile
|
68
67
|
- changelog.md
|
@@ -118,6 +117,7 @@ files:
|
|
118
117
|
- ext/bigdecimal/math_r/api/numeric/abs.h
|
119
118
|
- ext/bigdecimal/math_r/api/numeric/canonicalize.h
|
120
119
|
- ext/bigdecimal/math_r/api/numeric/cmpeql.h
|
120
|
+
- ext/bigdecimal/math_r/api/numeric/domain_p.h
|
121
121
|
- ext/bigdecimal/math_r/api/numeric/equal_p.h
|
122
122
|
- ext/bigdecimal/math_r/api/numeric/finite_p.h
|
123
123
|
- ext/bigdecimal/math_r/api/numeric/imag.h
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2025 tribusonz-2
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|