bigdecimal 1.4.3.pre.20190110 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bigdecimal.gemspec +5 -11
- data/ext/bigdecimal/bigdecimal.c +245 -77
- data/ext/bigdecimal/bigdecimal.h +4 -0
- data/ext/bigdecimal/extconf.rb +22 -5
- data/lib/bigdecimal.rb +1 -22
- data/lib/bigdecimal/jacobian.rb +3 -4
- data/lib/bigdecimal/util.rb +37 -2
- metadata +11 -30
- data/ext/bigdecimal/bigdecimal.def +0 -3
- data/ext/bigdecimal/depend +0 -16
- data/ext/bigdecimal/util/extconf.rb +0 -24
- data/ext/bigdecimal/util/util.c +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3519c64aa42c80e19107fc6d5d78d81385d7d71b9c09abef67c4e4c6a0bcef
|
4
|
+
data.tar.gz: 4ab9cb50f0a24014262635c07ecb42e6891326b49de50f262550e22d00c586ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4aa6023012625b46f68a9e58d79a5ea0aa2c579ddb4245e0753a01118d62bd75fa5a708535346ab295619aa2ad9974a929189a83a00d56321c295a1ec8498c
|
7
|
+
data.tar.gz: 5717f808a7a56ae06b5060a3752fcaf3a9b47dca9dceb8e6822e603ec20f0296b711df04d1454a309ac6720d4af60e9b4e58f3477133f7a66e20eab75207a70e
|
data/bigdecimal.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
bigdecimal_version = '
|
3
|
+
bigdecimal_version = '3.0.0'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "bigdecimal"
|
@@ -11,19 +11,14 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = "Arbitrary-precision decimal floating-point number library."
|
12
12
|
s.description = "This library provides arbitrary-precision decimal floating-point number class."
|
13
13
|
s.homepage = "https://github.com/ruby/bigdecimal"
|
14
|
-
s.license = "
|
14
|
+
s.license = "Ruby"
|
15
15
|
|
16
16
|
s.require_paths = %w[lib]
|
17
|
-
s.extensions = %w[ext/bigdecimal/extconf.rb
|
17
|
+
s.extensions = %w[ext/bigdecimal/extconf.rb]
|
18
18
|
s.files = %w[
|
19
19
|
bigdecimal.gemspec
|
20
20
|
ext/bigdecimal/bigdecimal.c
|
21
|
-
ext/bigdecimal/bigdecimal.def
|
22
21
|
ext/bigdecimal/bigdecimal.h
|
23
|
-
ext/bigdecimal/depend
|
24
|
-
ext/bigdecimal/extconf.rb
|
25
|
-
ext/bigdecimal/util/extconf.rb
|
26
|
-
ext/bigdecimal/util/util.c
|
27
22
|
lib/bigdecimal.rb
|
28
23
|
lib/bigdecimal/jacobian.rb
|
29
24
|
lib/bigdecimal/ludcmp.rb
|
@@ -35,11 +30,10 @@ Gem::Specification.new do |s|
|
|
35
30
|
sample/pi.rb
|
36
31
|
]
|
37
32
|
|
38
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.
|
33
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
39
34
|
|
40
|
-
s.add_development_dependency "rake", "
|
35
|
+
s.add_development_dependency "rake", ">= 12.3.3"
|
41
36
|
s.add_development_dependency "rake-compiler", ">= 0.9"
|
42
|
-
s.add_development_dependency "rake-compiler-dock", ">= 0.6.1"
|
43
37
|
s.add_development_dependency "minitest", "< 5.0.0"
|
44
38
|
s.add_development_dependency "pry"
|
45
39
|
end
|
data/ext/bigdecimal/bigdecimal.c
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
#include "ruby/util.h"
|
15
15
|
|
16
16
|
#ifndef BIGDECIMAL_DEBUG
|
17
|
+
# undef NDEBUG
|
17
18
|
# define NDEBUG
|
18
19
|
#endif
|
19
20
|
#include <assert.h>
|
@@ -24,7 +25,6 @@
|
|
24
25
|
#include <string.h>
|
25
26
|
#include <errno.h>
|
26
27
|
#include <math.h>
|
27
|
-
#include "math.h"
|
28
28
|
|
29
29
|
#ifdef HAVE_IEEEFP_H
|
30
30
|
#include <ieeefp.h>
|
@@ -77,7 +77,7 @@ static ID id_half;
|
|
77
77
|
#define BASE1 (BASE/10)
|
78
78
|
|
79
79
|
#ifndef DBLE_FIG
|
80
|
-
#define DBLE_FIG (
|
80
|
+
#define DBLE_FIG rmpd_double_figures() /* figure of double */
|
81
81
|
#endif
|
82
82
|
|
83
83
|
#ifndef RRATIONAL_ZERO_P
|
@@ -127,6 +127,30 @@ rb_rational_den(VALUE rat)
|
|
127
127
|
}
|
128
128
|
#endif
|
129
129
|
|
130
|
+
#ifndef HAVE_RB_COMPLEX_REAL
|
131
|
+
static inline VALUE
|
132
|
+
rb_complex_real(VALUE cmp)
|
133
|
+
{
|
134
|
+
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
|
135
|
+
return RCOMPLEX(cmp)->real;
|
136
|
+
#else
|
137
|
+
return rb_funcall(cmp, rb_intern("real"), 0);
|
138
|
+
#endif
|
139
|
+
}
|
140
|
+
#endif
|
141
|
+
|
142
|
+
#ifndef HAVE_RB_COMPLEX_IMAG
|
143
|
+
static inline VALUE
|
144
|
+
rb_complex_imag(VALUE cmp)
|
145
|
+
{
|
146
|
+
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
|
147
|
+
return RCOMPLEX(cmp)->imag;
|
148
|
+
#else
|
149
|
+
return rb_funcall(cmp, rb_intern("imag"), 0);
|
150
|
+
#endif
|
151
|
+
}
|
152
|
+
#endif
|
153
|
+
|
130
154
|
#define BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0)
|
131
155
|
#define BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0)
|
132
156
|
|
@@ -165,11 +189,16 @@ BigDecimal_memsize(const void *ptr)
|
|
165
189
|
return (sizeof(*pv) + pv->MaxPrec * sizeof(BDIGIT));
|
166
190
|
}
|
167
191
|
|
192
|
+
#ifndef HAVE_RB_EXT_RACTOR_SAFE
|
193
|
+
# undef RUBY_TYPED_FROZEN_SHAREABLE
|
194
|
+
# define RUBY_TYPED_FROZEN_SHAREABLE 0
|
195
|
+
#endif
|
196
|
+
|
168
197
|
static const rb_data_type_t BigDecimal_data_type = {
|
169
198
|
"BigDecimal",
|
170
199
|
{ 0, BigDecimal_delete, BigDecimal_memsize, },
|
171
200
|
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
172
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
201
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE
|
173
202
|
#endif
|
174
203
|
};
|
175
204
|
|
@@ -228,7 +257,7 @@ again:
|
|
228
257
|
switch(TYPE(v)) {
|
229
258
|
case T_FLOAT:
|
230
259
|
if (prec < 0) goto unable_to_coerce_without_prec;
|
231
|
-
if (prec >
|
260
|
+
if (prec > (long)DBLE_FIG) goto SomeOneMayDoIt;
|
232
261
|
d = RFLOAT_VALUE(v);
|
233
262
|
if (!isfinite(d)) {
|
234
263
|
pv = VpCreateRbObject(1, NULL);
|
@@ -276,7 +305,6 @@ again:
|
|
276
305
|
#ifdef ENABLE_NUMERIC_STRING
|
277
306
|
case T_STRING:
|
278
307
|
StringValueCStr(v);
|
279
|
-
rb_check_safe_obj(v);
|
280
308
|
return VpCreateRbObject(RSTRING_LEN(v) + VpBaseFig() + 1,
|
281
309
|
RSTRING_PTR(v));
|
282
310
|
#endif /* ENABLE_NUMERIC_STRING */
|
@@ -327,11 +355,13 @@ BigDecimal_double_fig(VALUE self)
|
|
327
355
|
/* call-seq:
|
328
356
|
* big_decimal.precs -> array
|
329
357
|
*
|
330
|
-
* Returns an Array of two Integer values
|
358
|
+
* Returns an Array of two Integer values that represent platform-dependent
|
359
|
+
* internal storage properties.
|
331
360
|
*
|
332
|
-
*
|
333
|
-
*
|
334
|
-
*
|
361
|
+
* This method is deprecated and will be removed in the future.
|
362
|
+
* Instead, use BigDecimal#n_significant_digits for obtaining the number of
|
363
|
+
* significant digits in scientific notation, and BigDecimal#precision for
|
364
|
+
* obtaining the number of digits in decimal notation.
|
335
365
|
*
|
336
366
|
* BigDecimal('5').precs #=> [9, 18]
|
337
367
|
*/
|
@@ -343,12 +373,109 @@ BigDecimal_prec(VALUE self)
|
|
343
373
|
Real *p;
|
344
374
|
VALUE obj;
|
345
375
|
|
376
|
+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
|
377
|
+
"BigDecimal#precs is deprecated and will be removed in the future; "
|
378
|
+
"use BigDecimal#precision instead.");
|
379
|
+
|
346
380
|
GUARD_OBJ(p, GetVpValue(self, 1));
|
347
|
-
obj = rb_assoc_new(
|
348
|
-
|
381
|
+
obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()),
|
382
|
+
SIZET2NUM(p->MaxPrec*VpBaseFig()));
|
349
383
|
return obj;
|
350
384
|
}
|
351
385
|
|
386
|
+
/*
|
387
|
+
* call-seq:
|
388
|
+
* big_decimal.precision -> intreger
|
389
|
+
*
|
390
|
+
* Returns the number of decimal digits in this number.
|
391
|
+
*
|
392
|
+
* Example:
|
393
|
+
*
|
394
|
+
* BigDecimal("0").precision # => 0
|
395
|
+
* BigDecimal("1").precision # => 1
|
396
|
+
* BigDecimal("-1e20").precision # => 21
|
397
|
+
* BigDecimal("1e-20").precision # => 20
|
398
|
+
* BigDecimal("Infinity").precision # => 0
|
399
|
+
* BigDecimal("-Infinity").precision # => 0
|
400
|
+
* BigDecimal("NaN").precision # => 0
|
401
|
+
*/
|
402
|
+
static VALUE
|
403
|
+
BigDecimal_precision(VALUE self)
|
404
|
+
{
|
405
|
+
ENTER(1);
|
406
|
+
|
407
|
+
Real *p;
|
408
|
+
GUARD_OBJ(p, GetVpValue(self, 1));
|
409
|
+
|
410
|
+
/*
|
411
|
+
* The most significant digit is frac[0], and the least significant digit is frac[Prec-1].
|
412
|
+
* When the exponent is zero, the decimal point is located just before frac[0].
|
413
|
+
* When the exponent is negative, the decimal point moves to leftward.
|
414
|
+
* Conversely, when the exponent is positive, the decimal point moves to rightward.
|
415
|
+
*
|
416
|
+
* | frac[0] frac[1] frac[2] . frac[3] frac[4] ... frac[Prec-1]
|
417
|
+
* |------------------------> exponent == 3
|
418
|
+
*/
|
419
|
+
|
420
|
+
ssize_t ex = p->exponent;
|
421
|
+
ssize_t precision;
|
422
|
+
if (ex < 0) {
|
423
|
+
precision = (-ex + 1) * BASE_FIG; /* 1 is for p->frac[0] */
|
424
|
+
ex = 0;
|
425
|
+
}
|
426
|
+
else if (p->Prec > 0) {
|
427
|
+
BDIGIT x = p->frac[0];
|
428
|
+
for (precision = 0; x > 0; x /= 10) {
|
429
|
+
++precision;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
if (ex > (ssize_t)p->Prec) {
|
434
|
+
precision += (ex - 1) * BASE_FIG;
|
435
|
+
}
|
436
|
+
else if (p->Prec > 0) {
|
437
|
+
ssize_t n = (ssize_t)p->Prec - 1;
|
438
|
+
while (n > 0 && p->frac[n] == 0) --n;
|
439
|
+
|
440
|
+
precision += n * BASE_FIG;
|
441
|
+
|
442
|
+
if (ex < (ssize_t)p->Prec) {
|
443
|
+
BDIGIT x = p->frac[n];
|
444
|
+
for (; x > 0 && x % 10 == 0; x /= 10) {
|
445
|
+
--precision;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
}
|
449
|
+
|
450
|
+
return SSIZET2NUM(precision);
|
451
|
+
}
|
452
|
+
|
453
|
+
static VALUE
|
454
|
+
BigDecimal_n_significant_digits(VALUE self)
|
455
|
+
{
|
456
|
+
ENTER(1);
|
457
|
+
|
458
|
+
Real *p;
|
459
|
+
GUARD_OBJ(p, GetVpValue(self, 1));
|
460
|
+
|
461
|
+
ssize_t n = p->Prec;
|
462
|
+
while (n > 0 && p->frac[n-1] == 0) --n;
|
463
|
+
if (n <= 0) {
|
464
|
+
return INT2FIX(0);
|
465
|
+
}
|
466
|
+
|
467
|
+
int nlz, ntz;
|
468
|
+
|
469
|
+
BDIGIT x = p->frac[0];
|
470
|
+
for (nlz = BASE_FIG; x > 0; x /= 10) --nlz;
|
471
|
+
|
472
|
+
x = p->frac[n-1];
|
473
|
+
for (ntz = 0; x > 0 && x % 10 == 0; x /= 10) ++ntz;
|
474
|
+
|
475
|
+
ssize_t n_digits = BASE_FIG * n - nlz - ntz;
|
476
|
+
return SSIZET2NUM(n_digits);
|
477
|
+
}
|
478
|
+
|
352
479
|
/*
|
353
480
|
* call-seq: hash
|
354
481
|
*
|
@@ -418,7 +545,6 @@ BigDecimal_load(VALUE self, VALUE str)
|
|
418
545
|
unsigned long m=0;
|
419
546
|
|
420
547
|
pch = (unsigned char *)StringValueCStr(str);
|
421
|
-
rb_check_safe_obj(str);
|
422
548
|
/* First get max prec */
|
423
549
|
while((*pch) != (unsigned char)'\0' && (ch = *pch++) != (unsigned char)':') {
|
424
550
|
if(!ISDIGIT(ch)) {
|
@@ -877,7 +1003,7 @@ BigDecimal_coerce(VALUE self, VALUE other)
|
|
877
1003
|
Real *b;
|
878
1004
|
|
879
1005
|
if (RB_TYPE_P(other, T_FLOAT)) {
|
880
|
-
GUARD_OBJ(b, GetVpValueWithPrec(other,
|
1006
|
+
GUARD_OBJ(b, GetVpValueWithPrec(other, DBLE_FIG, 1));
|
881
1007
|
obj = rb_assoc_new(ToValue(b), self);
|
882
1008
|
}
|
883
1009
|
else {
|
@@ -935,7 +1061,7 @@ BigDecimal_add(VALUE self, VALUE r)
|
|
935
1061
|
|
936
1062
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
937
1063
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
938
|
-
b = GetVpValueWithPrec(r,
|
1064
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
939
1065
|
}
|
940
1066
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
941
1067
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -993,7 +1119,7 @@ BigDecimal_sub(VALUE self, VALUE r)
|
|
993
1119
|
|
994
1120
|
GUARD_OBJ(a, GetVpValue(self,1));
|
995
1121
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
996
|
-
b = GetVpValueWithPrec(r,
|
1122
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
997
1123
|
}
|
998
1124
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
999
1125
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1043,7 +1169,7 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
|
|
1043
1169
|
break;
|
1044
1170
|
|
1045
1171
|
case T_FLOAT:
|
1046
|
-
GUARD_OBJ(b, GetVpValueWithPrec(r,
|
1172
|
+
GUARD_OBJ(b, GetVpValueWithPrec(r, DBLE_FIG, 0));
|
1047
1173
|
break;
|
1048
1174
|
|
1049
1175
|
case T_RATIONAL:
|
@@ -1256,7 +1382,7 @@ BigDecimal_mult(VALUE self, VALUE r)
|
|
1256
1382
|
|
1257
1383
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1258
1384
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1259
|
-
|
1385
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1260
1386
|
}
|
1261
1387
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1262
1388
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1284,7 +1410,7 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)
|
|
1284
1410
|
|
1285
1411
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1286
1412
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1287
|
-
|
1413
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1288
1414
|
}
|
1289
1415
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1290
1416
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1350,7 +1476,7 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
|
|
1350
1476
|
|
1351
1477
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1352
1478
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1353
|
-
b = GetVpValueWithPrec(r,
|
1479
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1354
1480
|
}
|
1355
1481
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1356
1482
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1451,7 +1577,7 @@ BigDecimal_divremain(VALUE self, VALUE r, Real **dv, Real **rv)
|
|
1451
1577
|
|
1452
1578
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1453
1579
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1454
|
-
b = GetVpValueWithPrec(r,
|
1580
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1455
1581
|
}
|
1456
1582
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1457
1583
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1756,20 +1882,23 @@ BigDecimal_fix(VALUE self)
|
|
1756
1882
|
* round(n, mode)
|
1757
1883
|
*
|
1758
1884
|
* Round to the nearest integer (by default), returning the result as a
|
1759
|
-
* BigDecimal.
|
1885
|
+
* BigDecimal if n is specified, or as an Integer if it isn't.
|
1760
1886
|
*
|
1761
1887
|
* BigDecimal('3.14159').round #=> 3
|
1762
1888
|
* BigDecimal('8.7').round #=> 9
|
1763
1889
|
* BigDecimal('-9.9').round #=> -10
|
1764
1890
|
*
|
1891
|
+
* BigDecimal('3.14159').round(2).class.name #=> "BigDecimal"
|
1892
|
+
* BigDecimal('3.14159').round.class.name #=> "Integer"
|
1893
|
+
*
|
1765
1894
|
* If n is specified and positive, the fractional part of the result has no
|
1766
1895
|
* more than that many digits.
|
1767
1896
|
*
|
1768
1897
|
* If n is specified and negative, at least that many digits to the left of the
|
1769
|
-
* decimal point will be 0 in the result.
|
1898
|
+
* decimal point will be 0 in the result, and return value will be an Integer.
|
1770
1899
|
*
|
1771
1900
|
* BigDecimal('3.14159').round(3) #=> 3.142
|
1772
|
-
* BigDecimal('13345.234').round(-2) #=> 13300
|
1901
|
+
* BigDecimal('13345.234').round(-2) #=> 13300
|
1773
1902
|
*
|
1774
1903
|
* The value of the optional mode argument can be used to determine how
|
1775
1904
|
* rounding is performed; see BigDecimal.mode.
|
@@ -1782,6 +1911,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
|
|
1782
1911
|
int iLoc = 0;
|
1783
1912
|
VALUE vLoc;
|
1784
1913
|
VALUE vRound;
|
1914
|
+
int round_to_int = 0;
|
1785
1915
|
size_t mx, pl;
|
1786
1916
|
|
1787
1917
|
unsigned short sw = VpGetRoundMode();
|
@@ -1789,6 +1919,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
|
|
1789
1919
|
switch (rb_scan_args(argc, argv, "02", &vLoc, &vRound)) {
|
1790
1920
|
case 0:
|
1791
1921
|
iLoc = 0;
|
1922
|
+
round_to_int = 1;
|
1792
1923
|
break;
|
1793
1924
|
case 1:
|
1794
1925
|
if (RB_TYPE_P(vLoc, T_HASH)) {
|
@@ -1796,6 +1927,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
|
|
1796
1927
|
}
|
1797
1928
|
else {
|
1798
1929
|
iLoc = NUM2INT(vLoc);
|
1930
|
+
if (iLoc < 1) round_to_int = 1;
|
1799
1931
|
}
|
1800
1932
|
break;
|
1801
1933
|
case 2:
|
@@ -1817,7 +1949,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
|
|
1817
1949
|
GUARD_OBJ(c, VpCreateRbObject(mx, "0"));
|
1818
1950
|
VpSetPrecLimit(pl);
|
1819
1951
|
VpActiveRound(c, a, sw, iLoc);
|
1820
|
-
if (
|
1952
|
+
if (round_to_int) {
|
1821
1953
|
return BigDecimal_to_i(ToValue(c));
|
1822
1954
|
}
|
1823
1955
|
return ToValue(c);
|
@@ -2027,7 +2159,6 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
|
|
2027
2159
|
if (rb_scan_args(argc, argv, "01", &f) == 1) {
|
2028
2160
|
if (RB_TYPE_P(f, T_STRING)) {
|
2029
2161
|
psz = StringValueCStr(f);
|
2030
|
-
rb_check_safe_obj(f);
|
2031
2162
|
if (*psz == ' ') {
|
2032
2163
|
fPlus = 1;
|
2033
2164
|
psz++;
|
@@ -2067,7 +2198,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
|
|
2067
2198
|
nc += (nc + mc - 1) / mc + 1;
|
2068
2199
|
}
|
2069
2200
|
|
2070
|
-
str =
|
2201
|
+
str = rb_usascii_str_new(0, nc);
|
2071
2202
|
psz = RSTRING_PTR(str);
|
2072
2203
|
|
2073
2204
|
if (fmt) {
|
@@ -2132,7 +2263,7 @@ BigDecimal_split(VALUE self)
|
|
2132
2263
|
rb_ary_push(obj, str);
|
2133
2264
|
rb_str_resize(str, strlen(psz1));
|
2134
2265
|
rb_ary_push(obj, INT2FIX(10));
|
2135
|
-
rb_ary_push(obj,
|
2266
|
+
rb_ary_push(obj, SSIZET2NUM(e));
|
2136
2267
|
return obj;
|
2137
2268
|
}
|
2138
2269
|
|
@@ -2145,7 +2276,7 @@ static VALUE
|
|
2145
2276
|
BigDecimal_exponent(VALUE self)
|
2146
2277
|
{
|
2147
2278
|
ssize_t e = VpExponent10(GetVpValue(self, 1));
|
2148
|
-
return
|
2279
|
+
return SSIZET2NUM(e);
|
2149
2280
|
}
|
2150
2281
|
|
2151
2282
|
/* Returns a string representation of self.
|
@@ -2338,7 +2469,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
|
|
2338
2469
|
}
|
2339
2470
|
goto retry;
|
2340
2471
|
}
|
2341
|
-
|
2472
|
+
if (NIL_P(prec)) {
|
2473
|
+
n += DBLE_FIG;
|
2474
|
+
}
|
2475
|
+
exp = GetVpValueWithPrec(vexp, DBLE_FIG, 1);
|
2342
2476
|
break;
|
2343
2477
|
|
2344
2478
|
case T_RATIONAL:
|
@@ -2353,6 +2487,9 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
|
|
2353
2487
|
goto retry;
|
2354
2488
|
}
|
2355
2489
|
exp = GetVpValueWithPrec(vexp, n, 1);
|
2490
|
+
if (NIL_P(prec)) {
|
2491
|
+
n += n;
|
2492
|
+
}
|
2356
2493
|
break;
|
2357
2494
|
|
2358
2495
|
case T_DATA:
|
@@ -2363,6 +2500,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
|
|
2363
2500
|
vexp = BigDecimal_to_i(vexp);
|
2364
2501
|
goto retry;
|
2365
2502
|
}
|
2503
|
+
if (NIL_P(prec)) {
|
2504
|
+
GUARD_OBJ(y, GetVpValue(vexp, 1));
|
2505
|
+
n += y->Prec*VpBaseFig();
|
2506
|
+
}
|
2366
2507
|
exp = DATA_PTR(vexp);
|
2367
2508
|
break;
|
2368
2509
|
}
|
@@ -2560,6 +2701,10 @@ BigDecimal_clone(VALUE self)
|
|
2560
2701
|
return self;
|
2561
2702
|
}
|
2562
2703
|
|
2704
|
+
#ifdef HAVE_RB_OPTS_EXCEPTION_P
|
2705
|
+
int rb_opts_exception_p(VALUE opts, int default_value);
|
2706
|
+
#define opts_exception_p(opts) rb_opts_exception_p((opts), 1)
|
2707
|
+
#else
|
2563
2708
|
static int
|
2564
2709
|
opts_exception_p(VALUE opts)
|
2565
2710
|
{
|
@@ -2568,12 +2713,20 @@ opts_exception_p(VALUE opts)
|
|
2568
2713
|
if (!kwds[0]) {
|
2569
2714
|
kwds[0] = rb_intern_const("exception");
|
2570
2715
|
}
|
2571
|
-
rb_get_kwargs(opts, kwds, 0, 1, &exception);
|
2716
|
+
if (!rb_get_kwargs(opts, kwds, 0, 1, &exception)) return 1;
|
2717
|
+
switch (exception) {
|
2718
|
+
case Qtrue: case Qfalse:
|
2719
|
+
break;
|
2720
|
+
default:
|
2721
|
+
rb_raise(rb_eArgError, "true or false is expected as exception: %+"PRIsVALUE,
|
2722
|
+
exception);
|
2723
|
+
}
|
2572
2724
|
return exception != Qfalse;
|
2573
2725
|
}
|
2726
|
+
#endif
|
2574
2727
|
|
2575
2728
|
static Real *
|
2576
|
-
|
2729
|
+
VpNewVarArg(int argc, VALUE *argv)
|
2577
2730
|
{
|
2578
2731
|
size_t mf;
|
2579
2732
|
VALUE opts = Qnil;
|
@@ -2616,6 +2769,7 @@ VpNewVarArgs(int argc, VALUE *argv)
|
|
2616
2769
|
}
|
2617
2770
|
}
|
2618
2771
|
|
2772
|
+
retry:
|
2619
2773
|
switch (TYPE(iniValue)) {
|
2620
2774
|
case T_DATA:
|
2621
2775
|
if (is_kind_of_BigDecimal(iniValue)) {
|
@@ -2635,7 +2789,7 @@ VpNewVarArgs(int argc, VALUE *argv)
|
|
2635
2789
|
VpDtoV(pv, d);
|
2636
2790
|
return pv;
|
2637
2791
|
}
|
2638
|
-
if (mf >
|
2792
|
+
if (mf > DBLE_FIG) {
|
2639
2793
|
if (!exc) {
|
2640
2794
|
return NULL;
|
2641
2795
|
}
|
@@ -2653,6 +2807,18 @@ VpNewVarArgs(int argc, VALUE *argv)
|
|
2653
2807
|
}
|
2654
2808
|
return GetVpValueWithPrec(iniValue, mf, 1);
|
2655
2809
|
|
2810
|
+
case T_COMPLEX:
|
2811
|
+
{
|
2812
|
+
VALUE im;
|
2813
|
+
im = rb_complex_imag(iniValue);
|
2814
|
+
if (!is_zero(im)) {
|
2815
|
+
rb_raise(rb_eArgError,
|
2816
|
+
"Unable to make a BigDecimal from non-zero imaginary number");
|
2817
|
+
}
|
2818
|
+
iniValue = rb_complex_real(iniValue);
|
2819
|
+
goto retry;
|
2820
|
+
}
|
2821
|
+
|
2656
2822
|
case T_STRING:
|
2657
2823
|
/* fall through */
|
2658
2824
|
default:
|
@@ -2667,23 +2833,6 @@ VpNewVarArgs(int argc, VALUE *argv)
|
|
2667
2833
|
return VpAlloc(mf, RSTRING_PTR(iniValue), 1, exc);
|
2668
2834
|
}
|
2669
2835
|
|
2670
|
-
static VALUE
|
2671
|
-
BigDecimal_new(int argc, VALUE *argv, VALUE klass)
|
2672
|
-
{
|
2673
|
-
ENTER(1);
|
2674
|
-
Real *pv;
|
2675
|
-
VALUE obj;
|
2676
|
-
|
2677
|
-
obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, 0);
|
2678
|
-
pv = VpNewVarArgs(argc, argv);
|
2679
|
-
if (pv == NULL) return Qnil;
|
2680
|
-
SAVE(pv);
|
2681
|
-
if (ToValue(pv)) pv = VpCopy(NULL, pv);
|
2682
|
-
RTYPEDDATA_DATA(obj) = pv;
|
2683
|
-
RB_OBJ_FREEZE(obj);
|
2684
|
-
return pv->obj = obj;
|
2685
|
-
}
|
2686
|
-
|
2687
2836
|
/* call-seq:
|
2688
2837
|
* BigDecimal(initial, digits, exception: true)
|
2689
2838
|
*
|
@@ -2723,14 +2872,35 @@ BigDecimal_new(int argc, VALUE *argv, VALUE klass)
|
|
2723
2872
|
static VALUE
|
2724
2873
|
f_BigDecimal(int argc, VALUE *argv, VALUE self)
|
2725
2874
|
{
|
2726
|
-
|
2875
|
+
ENTER(1);
|
2876
|
+
Real *pv;
|
2877
|
+
VALUE obj;
|
2878
|
+
|
2879
|
+
if (argc > 0 && CLASS_OF(argv[0]) == rb_cBigDecimal) {
|
2880
|
+
if (argc == 1 || (argc == 2 && RB_TYPE_P(argv[1], T_HASH))) return argv[0];
|
2881
|
+
}
|
2882
|
+
obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0);
|
2883
|
+
pv = VpNewVarArg(argc, argv);
|
2884
|
+
if (pv == NULL) return Qnil;
|
2885
|
+
SAVE(pv);
|
2886
|
+
if (ToValue(pv)) pv = VpCopy(NULL, pv);
|
2887
|
+
RTYPEDDATA_DATA(obj) = pv;
|
2888
|
+
RB_OBJ_FREEZE(obj);
|
2889
|
+
return pv->obj = obj;
|
2727
2890
|
}
|
2728
2891
|
|
2729
|
-
/* DEPRECATED: BigDecimal.new() */
|
2730
2892
|
static VALUE
|
2731
|
-
|
2893
|
+
BigDecimal_s_interpret_loosely(VALUE klass, VALUE str)
|
2732
2894
|
{
|
2733
|
-
|
2895
|
+
ENTER(1);
|
2896
|
+
char const *c_str;
|
2897
|
+
Real *pv;
|
2898
|
+
|
2899
|
+
c_str = StringValueCStr(str);
|
2900
|
+
GUARD_OBJ(pv, VpAlloc(0, c_str, 0, 1));
|
2901
|
+
pv->obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, pv);
|
2902
|
+
RB_OBJ_FREEZE(pv->obj);
|
2903
|
+
return pv->obj;
|
2734
2904
|
}
|
2735
2905
|
|
2736
2906
|
/* call-seq:
|
@@ -2749,7 +2919,7 @@ static VALUE
|
|
2749
2919
|
BigDecimal_limit(int argc, VALUE *argv, VALUE self)
|
2750
2920
|
{
|
2751
2921
|
VALUE nFig;
|
2752
|
-
VALUE nCur =
|
2922
|
+
VALUE nCur = SIZET2NUM(VpGetPrecLimit());
|
2753
2923
|
|
2754
2924
|
if (rb_scan_args(argc, argv, "01", &nFig) == 1) {
|
2755
2925
|
int nf;
|
@@ -2914,7 +3084,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
|
|
2914
3084
|
infinite = isinf(flo);
|
2915
3085
|
nan = isnan(flo);
|
2916
3086
|
if (!infinite && !nan) {
|
2917
|
-
vx = GetVpValueWithPrec(x,
|
3087
|
+
vx = GetVpValueWithPrec(x, DBLE_FIG, 0);
|
2918
3088
|
}
|
2919
3089
|
break;
|
2920
3090
|
|
@@ -2952,6 +3122,10 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
|
|
2952
3122
|
n = prec + rmpd_double_figures();
|
2953
3123
|
negative = BIGDECIMAL_NEGATIVE_P(vx);
|
2954
3124
|
if (negative) {
|
3125
|
+
VALUE x_zero = INT2NUM(1);
|
3126
|
+
VALUE x_copy = f_BigDecimal(1, &x_zero, klass);
|
3127
|
+
x = BigDecimal_initialize_copy(x_copy, x);
|
3128
|
+
vx = DATA_PTR(x);
|
2955
3129
|
VpSetSign(vx, 1);
|
2956
3130
|
}
|
2957
3131
|
|
@@ -3063,7 +3237,7 @@ get_vp_value:
|
|
3063
3237
|
infinite = isinf(flo);
|
3064
3238
|
nan = isnan(flo);
|
3065
3239
|
if (!zero && !negative && !infinite && !nan) {
|
3066
|
-
vx = GetVpValueWithPrec(x,
|
3240
|
+
vx = GetVpValueWithPrec(x, DBLE_FIG, 1);
|
3067
3241
|
}
|
3068
3242
|
break;
|
3069
3243
|
|
@@ -3153,20 +3327,6 @@ get_vp_value:
|
|
3153
3327
|
return y;
|
3154
3328
|
}
|
3155
3329
|
|
3156
|
-
VALUE
|
3157
|
-
rmpd_util_str_to_d(VALUE str)
|
3158
|
-
{
|
3159
|
-
ENTER(1);
|
3160
|
-
char const *c_str;
|
3161
|
-
Real *pv;
|
3162
|
-
|
3163
|
-
c_str = StringValueCStr(str);
|
3164
|
-
GUARD_OBJ(pv, VpAlloc(0, c_str, 0, 1));
|
3165
|
-
pv->obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, pv);
|
3166
|
-
RB_OBJ_FREEZE(pv->obj);
|
3167
|
-
return pv->obj;
|
3168
|
-
}
|
3169
|
-
|
3170
3330
|
/* Document-class: BigDecimal
|
3171
3331
|
* BigDecimal provides arbitrary-precision floating point decimal arithmetic.
|
3172
3332
|
*
|
@@ -3295,6 +3455,9 @@ rmpd_util_str_to_d(VALUE str)
|
|
3295
3455
|
void
|
3296
3456
|
Init_bigdecimal(void)
|
3297
3457
|
{
|
3458
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
3459
|
+
rb_ext_ractor_safe(true);
|
3460
|
+
#endif
|
3298
3461
|
VALUE arg;
|
3299
3462
|
|
3300
3463
|
id_BigDecimal_exception_mode = rb_intern_const("BigDecimal.exception_mode");
|
@@ -3311,8 +3474,9 @@ Init_bigdecimal(void)
|
|
3311
3474
|
rb_define_global_function("BigDecimal", f_BigDecimal, -1);
|
3312
3475
|
|
3313
3476
|
/* Class methods */
|
3314
|
-
|
3315
|
-
|
3477
|
+
rb_undef_alloc_func(rb_cBigDecimal);
|
3478
|
+
rb_undef_method(CLASS_OF(rb_cBigDecimal), "new");
|
3479
|
+
rb_define_singleton_method(rb_cBigDecimal, "interpret_loosely", BigDecimal_s_interpret_loosely, 1);
|
3316
3480
|
rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
|
3317
3481
|
rb_define_singleton_method(rb_cBigDecimal, "limit", BigDecimal_limit, -1);
|
3318
3482
|
rb_define_singleton_method(rb_cBigDecimal, "double_fig", BigDecimal_double_fig, 0);
|
@@ -3443,8 +3607,9 @@ Init_bigdecimal(void)
|
|
3443
3607
|
|
3444
3608
|
|
3445
3609
|
/* instance methods */
|
3446
|
-
rb_define_method(rb_cBigDecimal, "initialize_copy", BigDecimal_initialize_copy, 1);
|
3447
3610
|
rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0);
|
3611
|
+
rb_define_method(rb_cBigDecimal, "precision", BigDecimal_precision, 0);
|
3612
|
+
rb_define_method(rb_cBigDecimal, "n_significant_digits", BigDecimal_n_significant_digits, 0);
|
3448
3613
|
|
3449
3614
|
rb_define_method(rb_cBigDecimal, "add", BigDecimal_add2, 2);
|
3450
3615
|
rb_define_method(rb_cBigDecimal, "sub", BigDecimal_sub2, 2);
|
@@ -3561,6 +3726,9 @@ static void VpFormatSt(char *psz, size_t fFmt);
|
|
3561
3726
|
static int VpRdup(Real *m, size_t ind_m);
|
3562
3727
|
|
3563
3728
|
#ifdef BIGDECIMAL_DEBUG
|
3729
|
+
# ifdef HAVE_RB_EXT_RACTOR_SAFE
|
3730
|
+
# error Need to make rewiting gnAlloc atomic
|
3731
|
+
# endif
|
3564
3732
|
static int gnAlloc = 0; /* Memory allocation counter */
|
3565
3733
|
#endif /* BIGDECIMAL_DEBUG */
|
3566
3734
|
|
@@ -3967,7 +4135,7 @@ VpNumOfChars(Real *vp,const char *pszFmt)
|
|
3967
4135
|
* by one BDIGIT word in the computer used.
|
3968
4136
|
*
|
3969
4137
|
* [Returns]
|
3970
|
-
*
|
4138
|
+
* DBLE_FIG ... OK
|
3971
4139
|
*/
|
3972
4140
|
VP_EXPORT size_t
|
3973
4141
|
VpInit(BDIGIT BaseVal)
|
@@ -4137,7 +4305,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
4137
4305
|
/* at least mx digits. */
|
4138
4306
|
/* szVal==NULL ==> allocate zero value. */
|
4139
4307
|
vp = VpAllocReal(mx);
|
4140
|
-
/* xmalloc()
|
4308
|
+
/* xmalloc() always returns(or throw interruption) */
|
4141
4309
|
vp->MaxPrec = mx; /* set max precision */
|
4142
4310
|
VpSetZero(vp, 1); /* initialize vp to zero. */
|
4143
4311
|
return vp;
|
@@ -4294,7 +4462,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
4294
4462
|
|
4295
4463
|
psz[i] = '\0';
|
4296
4464
|
|
4297
|
-
if (((ni == 0 || dot_seen) && nf == 0) || (exp_seen && ne == 0)) {
|
4465
|
+
if (strict_p && (((ni == 0 || dot_seen) && nf == 0) || (exp_seen && ne == 0))) {
|
4298
4466
|
VALUE str;
|
4299
4467
|
invalid_value:
|
4300
4468
|
if (!strict_p) {
|
@@ -4313,7 +4481,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
4313
4481
|
nalloc = Max(nalloc, mx);
|
4314
4482
|
mx = nalloc;
|
4315
4483
|
vp = VpAllocReal(mx);
|
4316
|
-
/* xmalloc()
|
4484
|
+
/* xmalloc() always returns(or throw interruption) */
|
4317
4485
|
vp->MaxPrec = mx; /* set max precision */
|
4318
4486
|
VpSetZero(vp, sign);
|
4319
4487
|
VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne);
|
data/ext/bigdecimal/bigdecimal.h
CHANGED
@@ -159,6 +159,10 @@ rb_sym2str(VALUE sym)
|
|
159
159
|
# define vabs llabs
|
160
160
|
#endif
|
161
161
|
|
162
|
+
#if !defined(HAVE_RB_CATEGORY_WARN) || !defined(HAVE_CONST_RB_WARN_CATEGORY_DEPRECATED)
|
163
|
+
# define rb_category_warn(category, ...) rb_warn(__VA_ARGS__)
|
164
|
+
#endif
|
165
|
+
|
162
166
|
extern VALUE rb_cBigDecimal;
|
163
167
|
|
164
168
|
#if 0 || SIZEOF_BDIGITS >= 16
|
data/ext/bigdecimal/extconf.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
require 'mkmf'
|
3
3
|
|
4
|
+
def check_bigdecimal_version(gemspec_path)
|
5
|
+
message "checking RUBY_BIGDECIMAL_VERSION... "
|
6
|
+
|
7
|
+
bigdecimal_version =
|
8
|
+
IO.readlines(gemspec_path)
|
9
|
+
.grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([^\']+)\'/, 1]
|
10
|
+
|
11
|
+
version_components = bigdecimal_version.split('.')
|
12
|
+
bigdecimal_version = version_components[0, 3].join('.')
|
13
|
+
bigdecimal_version << "-#{version_components[3]}" if version_components[3]
|
14
|
+
$defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
|
15
|
+
|
16
|
+
message "#{bigdecimal_version}\n"
|
17
|
+
end
|
18
|
+
|
4
19
|
gemspec_name = gemspec_path = nil
|
5
20
|
unless ['', '../../'].any? {|dir|
|
6
21
|
gemspec_name = "#{dir}bigdecimal.gemspec"
|
@@ -11,11 +26,7 @@ unless ['', '../../'].any? {|dir|
|
|
11
26
|
abort
|
12
27
|
end
|
13
28
|
|
14
|
-
|
15
|
-
IO.readlines(gemspec_path)
|
16
|
-
.grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([\d\.]+)\'/, 1]
|
17
|
-
|
18
|
-
$defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
|
29
|
+
check_bigdecimal_version(gemspec_path)
|
19
30
|
|
20
31
|
have_func("labs", "stdlib.h")
|
21
32
|
have_func("llabs", "stdlib.h")
|
@@ -25,8 +36,14 @@ have_func("isfinite", "math.h")
|
|
25
36
|
have_type("struct RRational", "ruby.h")
|
26
37
|
have_func("rb_rational_num", "ruby.h")
|
27
38
|
have_func("rb_rational_den", "ruby.h")
|
39
|
+
have_type("struct RComplex", "ruby.h")
|
40
|
+
have_func("rb_complex_real", "ruby.h")
|
41
|
+
have_func("rb_complex_imag", "ruby.h")
|
28
42
|
have_func("rb_array_const_ptr", "ruby.h")
|
29
43
|
have_func("rb_sym2str", "ruby.h")
|
44
|
+
have_func("rb_opts_exception_p", "ruby.h")
|
45
|
+
have_func("rb_category_warn", "ruby.h")
|
46
|
+
have_const("RB_WARN_CATEGORY_DEPRECATED", "ruby.h")
|
30
47
|
|
31
48
|
if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__))
|
32
49
|
bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb"
|
data/lib/bigdecimal.rb
CHANGED
@@ -1,22 +1 @@
|
|
1
|
-
|
2
|
-
require "#{RUBY_VERSION[/\d+\.\d+/]}/bigdecimal.so"
|
3
|
-
rescue LoadError
|
4
|
-
require 'bigdecimal.so'
|
5
|
-
end
|
6
|
-
|
7
|
-
class BigDecimal
|
8
|
-
module Deprecation
|
9
|
-
def new(*args, **kwargs)
|
10
|
-
warn "BigDecimal.new is deprecated; use BigDecimal() method instead.", uplevel: 1
|
11
|
-
super
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class << self
|
16
|
-
prepend Deprecation
|
17
|
-
|
18
|
-
def inherited(subclass)
|
19
|
-
warn "subclassing BigDecimal will be disallowed after bigdecimal version 2.0", uplevel: 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require 'bigdecimal.so'
|
data/lib/bigdecimal/jacobian.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
-
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
3
5
|
# require 'bigdecimal/jacobian'
|
4
6
|
#
|
5
7
|
# Provides methods to compute the Jacobian matrix of a set of equations at a
|
@@ -21,9 +23,6 @@
|
|
21
23
|
#
|
22
24
|
# fx is f.values(x).
|
23
25
|
#
|
24
|
-
|
25
|
-
require 'bigdecimal'
|
26
|
-
|
27
26
|
module Jacobian
|
28
27
|
module_function
|
29
28
|
|
data/lib/bigdecimal/util.rb
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
#++
|
7
7
|
|
8
8
|
require 'bigdecimal'
|
9
|
-
require 'bigdecimal/util.so'
|
10
9
|
|
11
10
|
class Integer < Numeric
|
12
11
|
# call-seq:
|
@@ -44,7 +43,7 @@ class Float < Numeric
|
|
44
43
|
#
|
45
44
|
# See also BigDecimal::new.
|
46
45
|
#
|
47
|
-
def to_d(precision=Float::DIG)
|
46
|
+
def to_d(precision=Float::DIG+1)
|
48
47
|
BigDecimal(self, precision)
|
49
48
|
end
|
50
49
|
end
|
@@ -66,6 +65,9 @@ class String
|
|
66
65
|
#
|
67
66
|
# See also BigDecimal::new.
|
68
67
|
#
|
68
|
+
def to_d
|
69
|
+
BigDecimal.interpret_loosely(self)
|
70
|
+
end
|
69
71
|
end
|
70
72
|
|
71
73
|
|
@@ -129,6 +131,39 @@ class Rational < Numeric
|
|
129
131
|
end
|
130
132
|
|
131
133
|
|
134
|
+
class Complex < Numeric
|
135
|
+
# call-seq:
|
136
|
+
# cmp.to_d -> bigdecimal
|
137
|
+
# cmp.to_d(precision) -> bigdecimal
|
138
|
+
#
|
139
|
+
# Returns the value as a BigDecimal.
|
140
|
+
#
|
141
|
+
# The +precision+ parameter is required for a rational complex number.
|
142
|
+
# This parameter is used to determine the number of significant digits
|
143
|
+
# for the result.
|
144
|
+
#
|
145
|
+
# require 'bigdecimal'
|
146
|
+
# require 'bigdecimal/util'
|
147
|
+
#
|
148
|
+
# Complex(0.1234567, 0).to_d(4) # => 0.1235e0
|
149
|
+
# Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
|
150
|
+
#
|
151
|
+
# See also BigDecimal::new.
|
152
|
+
#
|
153
|
+
def to_d(*args)
|
154
|
+
BigDecimal(self) unless self.imag.zero? # to raise eerror
|
155
|
+
|
156
|
+
if args.length == 0
|
157
|
+
case self.real
|
158
|
+
when Rational
|
159
|
+
BigDecimal(self.real) # to raise error
|
160
|
+
end
|
161
|
+
end
|
162
|
+
self.real.to_d(*args)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
|
132
167
|
class NilClass
|
133
168
|
# call-seq:
|
134
169
|
# nil.to_d -> bigdecimal
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigdecimal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-12-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 12.3.3
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 12.3.3
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rake-compiler
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,20 +40,6 @@ dependencies:
|
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0.9'
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: rake-compiler-dock
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 0.6.1
|
50
|
-
type: :development
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 0.6.1
|
57
43
|
- !ruby/object:Gem::Dependency
|
58
44
|
name: minitest
|
59
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,17 +75,12 @@ email:
|
|
89
75
|
executables: []
|
90
76
|
extensions:
|
91
77
|
- ext/bigdecimal/extconf.rb
|
92
|
-
- ext/bigdecimal/util/extconf.rb
|
93
78
|
extra_rdoc_files: []
|
94
79
|
files:
|
95
80
|
- bigdecimal.gemspec
|
96
81
|
- ext/bigdecimal/bigdecimal.c
|
97
|
-
- ext/bigdecimal/bigdecimal.def
|
98
82
|
- ext/bigdecimal/bigdecimal.h
|
99
|
-
- ext/bigdecimal/depend
|
100
83
|
- ext/bigdecimal/extconf.rb
|
101
|
-
- ext/bigdecimal/util/extconf.rb
|
102
|
-
- ext/bigdecimal/util/util.c
|
103
84
|
- lib/bigdecimal.rb
|
104
85
|
- lib/bigdecimal/jacobian.rb
|
105
86
|
- lib/bigdecimal/ludcmp.rb
|
@@ -111,7 +92,7 @@ files:
|
|
111
92
|
- sample/pi.rb
|
112
93
|
homepage: https://github.com/ruby/bigdecimal
|
113
94
|
licenses:
|
114
|
-
-
|
95
|
+
- Ruby
|
115
96
|
metadata: {}
|
116
97
|
post_install_message:
|
117
98
|
rdoc_options: []
|
@@ -121,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
102
|
requirements:
|
122
103
|
- - ">="
|
123
104
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
105
|
+
version: 2.4.0
|
125
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
107
|
requirements:
|
127
|
-
- - "
|
108
|
+
- - ">="
|
128
109
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
110
|
+
version: '0'
|
130
111
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.2.2
|
132
113
|
signing_key:
|
133
114
|
specification_version: 4
|
134
115
|
summary: Arbitrary-precision decimal floating-point number library.
|
data/ext/bigdecimal/depend
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
extconf.h: $(srcdir)/$(GEMSPEC)
|
2
|
-
Makefile: $(BIGDECIMAL_RB)
|
3
|
-
|
4
|
-
# AUTOGENERATED DEPENDENCIES START
|
5
|
-
bigdecimal.o: $(RUBY_EXTCONF_H)
|
6
|
-
bigdecimal.o: $(arch_hdrdir)/ruby/config.h
|
7
|
-
bigdecimal.o: $(hdrdir)/ruby/defines.h
|
8
|
-
bigdecimal.o: $(hdrdir)/ruby/intern.h
|
9
|
-
bigdecimal.o: $(hdrdir)/ruby/missing.h
|
10
|
-
bigdecimal.o: $(hdrdir)/ruby/ruby.h
|
11
|
-
bigdecimal.o: $(hdrdir)/ruby/st.h
|
12
|
-
bigdecimal.o: $(hdrdir)/ruby/subst.h
|
13
|
-
bigdecimal.o: $(hdrdir)/ruby/util.h
|
14
|
-
bigdecimal.o: bigdecimal.c
|
15
|
-
bigdecimal.o: bigdecimal.h
|
16
|
-
# AUTOGENERATED DEPENDENCIES END
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require 'mkmf'
|
3
|
-
|
4
|
-
checking_for(checking_message("Windows")) do
|
5
|
-
case RUBY_PLATFORM
|
6
|
-
when /cygwin|mingw/
|
7
|
-
if ARGV.include?('-rdevkit') # check `rake -rdevkit compile` case
|
8
|
-
base_dir = File.expand_path('../../../..', __FILE__)
|
9
|
-
build_dir = File.join(base_dir, "tmp", RUBY_PLATFORM, "bigdecimal", RUBY_VERSION, "")
|
10
|
-
else
|
11
|
-
build_dir = "$(TARGET_SO_DIR)../"
|
12
|
-
end
|
13
|
-
$libs << " #{build_dir}bigdecimal.so"
|
14
|
-
true
|
15
|
-
when /mswin/
|
16
|
-
$DLDFLAGS << " -libpath:.."
|
17
|
-
$libs << " bigdecimal-$(arch).lib"
|
18
|
-
true
|
19
|
-
else
|
20
|
-
false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
create_makefile('bigdecimal/util')
|