bigdecimal 2.0.2 → 2.0.3
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/bigdecimal.gemspec +1 -1
- data/ext/bigdecimal/bigdecimal.c +120 -19
- data/ext/bigdecimal/bigdecimal.h +4 -0
- data/ext/bigdecimal/extconf.rb +2 -0
- data/lib/bigdecimal/util.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef063cb7c648ba239e4179669ed4d410d9d160e293377ce4b1bdb73ec68366cb
|
4
|
+
data.tar.gz: d0e2d57a69c624ba2ef446c52fc19f889721809e7f6933ed8f0db684e3f9c1a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7fa4a273ccddcdc65fd477b8ff59abde5951966b45ea43b78b257eb69e10a3dece8f62cb37d34b68f02201fcf0e2e2d471b835660ddb4bab9a1e1bc74d7c22b
|
7
|
+
data.tar.gz: 3a2de54bf09de5ffc15f31227a1458ad670ddccefa716e48c06ca4f98709d4de068f72be0be603c9e5bf60191b91a54f1e13ef617bdde833e98740c6ad34faf9
|
data/bigdecimal.gemspec
CHANGED
data/ext/bigdecimal/bigdecimal.c
CHANGED
@@ -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
|
@@ -252,7 +252,7 @@ again:
|
|
252
252
|
switch(TYPE(v)) {
|
253
253
|
case T_FLOAT:
|
254
254
|
if (prec < 0) goto unable_to_coerce_without_prec;
|
255
|
-
if (prec >
|
255
|
+
if (prec > (long)DBLE_FIG) goto SomeOneMayDoIt;
|
256
256
|
d = RFLOAT_VALUE(v);
|
257
257
|
if (!isfinite(d)) {
|
258
258
|
pv = VpCreateRbObject(1, NULL);
|
@@ -350,11 +350,13 @@ BigDecimal_double_fig(VALUE self)
|
|
350
350
|
/* call-seq:
|
351
351
|
* big_decimal.precs -> array
|
352
352
|
*
|
353
|
-
* Returns an Array of two Integer values
|
353
|
+
* Returns an Array of two Integer values that represent platform-dependent
|
354
|
+
* internal storage properties.
|
354
355
|
*
|
355
|
-
*
|
356
|
-
*
|
357
|
-
*
|
356
|
+
* This method is deprecated and will be removed in the future.
|
357
|
+
* Instead, use BigDecimal#n_significant_digits for obtaining the number of
|
358
|
+
* significant digits in scientific notation, and BigDecimal#precision for
|
359
|
+
* obtaining the number of digits in decimal notation.
|
358
360
|
*
|
359
361
|
* BigDecimal('5').precs #=> [9, 18]
|
360
362
|
*/
|
@@ -366,12 +368,109 @@ BigDecimal_prec(VALUE self)
|
|
366
368
|
Real *p;
|
367
369
|
VALUE obj;
|
368
370
|
|
371
|
+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
|
372
|
+
"BigDecimal#precs is deprecated and will be removed in the future; "
|
373
|
+
"use BigDecimal#precision instead.");
|
374
|
+
|
369
375
|
GUARD_OBJ(p, GetVpValue(self, 1));
|
370
376
|
obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()),
|
371
377
|
SIZET2NUM(p->MaxPrec*VpBaseFig()));
|
372
378
|
return obj;
|
373
379
|
}
|
374
380
|
|
381
|
+
/*
|
382
|
+
* call-seq:
|
383
|
+
* big_decimal.precision -> intreger
|
384
|
+
*
|
385
|
+
* Returns the number of decimal digits in this number.
|
386
|
+
*
|
387
|
+
* Example:
|
388
|
+
*
|
389
|
+
* BigDecimal("0").precision # => 0
|
390
|
+
* BigDecimal("1").precision # => 1
|
391
|
+
* BigDecimal("-1e20").precision # => 21
|
392
|
+
* BigDecimal("1e-20").precision # => 20
|
393
|
+
* BigDecimal("Infinity").precision # => 0
|
394
|
+
* BigDecimal("-Infinity").precision # => 0
|
395
|
+
* BigDecimal("NaN").precision # => 0
|
396
|
+
*/
|
397
|
+
static VALUE
|
398
|
+
BigDecimal_precision(VALUE self)
|
399
|
+
{
|
400
|
+
ENTER(1);
|
401
|
+
|
402
|
+
Real *p;
|
403
|
+
GUARD_OBJ(p, GetVpValue(self, 1));
|
404
|
+
|
405
|
+
/*
|
406
|
+
* The most significant digit is frac[0], and the least significant digit is frac[Prec-1].
|
407
|
+
* When the exponent is zero, the decimal point is located just before frac[0].
|
408
|
+
* When the exponent is negative, the decimal point moves to leftward.
|
409
|
+
* Conversely, when the exponent is positive, the decimal point moves to rightward.
|
410
|
+
*
|
411
|
+
* | frac[0] frac[1] frac[2] . frac[3] frac[4] ... frac[Prec-1]
|
412
|
+
* |------------------------> exponent == 3
|
413
|
+
*/
|
414
|
+
|
415
|
+
ssize_t ex = p->exponent;
|
416
|
+
ssize_t precision;
|
417
|
+
if (ex < 0) {
|
418
|
+
precision = (-ex + 1) * BASE_FIG; /* 1 is for p->frac[0] */
|
419
|
+
ex = 0;
|
420
|
+
}
|
421
|
+
else if (p->Prec > 0) {
|
422
|
+
BDIGIT x = p->frac[0];
|
423
|
+
for (precision = 0; x > 0; x /= 10) {
|
424
|
+
++precision;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
if (ex > (ssize_t)p->Prec) {
|
429
|
+
precision += (ex - 1) * BASE_FIG;
|
430
|
+
}
|
431
|
+
else if (p->Prec > 0) {
|
432
|
+
ssize_t n = (ssize_t)p->Prec - 1;
|
433
|
+
while (n > 0 && p->frac[n] == 0) --n;
|
434
|
+
|
435
|
+
precision += n * BASE_FIG;
|
436
|
+
|
437
|
+
if (ex < (ssize_t)p->Prec) {
|
438
|
+
BDIGIT x = p->frac[n];
|
439
|
+
for (; x > 0 && x % 10 == 0; x /= 10) {
|
440
|
+
--precision;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
return SSIZET2NUM(precision);
|
446
|
+
}
|
447
|
+
|
448
|
+
static VALUE
|
449
|
+
BigDecimal_n_significant_digits(VALUE self)
|
450
|
+
{
|
451
|
+
ENTER(1);
|
452
|
+
|
453
|
+
Real *p;
|
454
|
+
GUARD_OBJ(p, GetVpValue(self, 1));
|
455
|
+
|
456
|
+
ssize_t n = p->Prec;
|
457
|
+
while (n > 0 && p->frac[n-1] == 0) --n;
|
458
|
+
if (n <= 0) {
|
459
|
+
return INT2FIX(0);
|
460
|
+
}
|
461
|
+
|
462
|
+
int nlz, ntz;
|
463
|
+
|
464
|
+
BDIGIT x = p->frac[0];
|
465
|
+
for (nlz = BASE_FIG; x > 0; x /= 10) --nlz;
|
466
|
+
|
467
|
+
x = p->frac[n-1];
|
468
|
+
for (ntz = 0; x > 0 && x % 10 == 0; x /= 10) ++ntz;
|
469
|
+
|
470
|
+
ssize_t n_digits = BASE_FIG * n - nlz - ntz;
|
471
|
+
return SSIZET2NUM(n_digits);
|
472
|
+
}
|
473
|
+
|
375
474
|
/*
|
376
475
|
* call-seq: hash
|
377
476
|
*
|
@@ -899,7 +998,7 @@ BigDecimal_coerce(VALUE self, VALUE other)
|
|
899
998
|
Real *b;
|
900
999
|
|
901
1000
|
if (RB_TYPE_P(other, T_FLOAT)) {
|
902
|
-
GUARD_OBJ(b, GetVpValueWithPrec(other,
|
1001
|
+
GUARD_OBJ(b, GetVpValueWithPrec(other, DBLE_FIG, 1));
|
903
1002
|
obj = rb_assoc_new(ToValue(b), self);
|
904
1003
|
}
|
905
1004
|
else {
|
@@ -957,7 +1056,7 @@ BigDecimal_add(VALUE self, VALUE r)
|
|
957
1056
|
|
958
1057
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
959
1058
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
960
|
-
b = GetVpValueWithPrec(r,
|
1059
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
961
1060
|
}
|
962
1061
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
963
1062
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1015,7 +1114,7 @@ BigDecimal_sub(VALUE self, VALUE r)
|
|
1015
1114
|
|
1016
1115
|
GUARD_OBJ(a, GetVpValue(self,1));
|
1017
1116
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1018
|
-
b = GetVpValueWithPrec(r,
|
1117
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1019
1118
|
}
|
1020
1119
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1021
1120
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1065,7 +1164,7 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
|
|
1065
1164
|
break;
|
1066
1165
|
|
1067
1166
|
case T_FLOAT:
|
1068
|
-
GUARD_OBJ(b, GetVpValueWithPrec(r,
|
1167
|
+
GUARD_OBJ(b, GetVpValueWithPrec(r, DBLE_FIG, 0));
|
1069
1168
|
break;
|
1070
1169
|
|
1071
1170
|
case T_RATIONAL:
|
@@ -1278,7 +1377,7 @@ BigDecimal_mult(VALUE self, VALUE r)
|
|
1278
1377
|
|
1279
1378
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1280
1379
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1281
|
-
|
1380
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1282
1381
|
}
|
1283
1382
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1284
1383
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1306,7 +1405,7 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)
|
|
1306
1405
|
|
1307
1406
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1308
1407
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1309
|
-
|
1408
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1310
1409
|
}
|
1311
1410
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1312
1411
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1372,7 +1471,7 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
|
|
1372
1471
|
|
1373
1472
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1374
1473
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1375
|
-
b = GetVpValueWithPrec(r,
|
1474
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1376
1475
|
}
|
1377
1476
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1378
1477
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -1473,7 +1572,7 @@ BigDecimal_divremain(VALUE self, VALUE r, Real **dv, Real **rv)
|
|
1473
1572
|
|
1474
1573
|
GUARD_OBJ(a, GetVpValue(self, 1));
|
1475
1574
|
if (RB_TYPE_P(r, T_FLOAT)) {
|
1476
|
-
b = GetVpValueWithPrec(r,
|
1575
|
+
b = GetVpValueWithPrec(r, DBLE_FIG, 1);
|
1477
1576
|
}
|
1478
1577
|
else if (RB_TYPE_P(r, T_RATIONAL)) {
|
1479
1578
|
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
|
@@ -2685,7 +2784,7 @@ VpNewVarArg(int argc, VALUE *argv)
|
|
2685
2784
|
VpDtoV(pv, d);
|
2686
2785
|
return pv;
|
2687
2786
|
}
|
2688
|
-
if (mf >
|
2787
|
+
if (mf > DBLE_FIG) {
|
2689
2788
|
if (!exc) {
|
2690
2789
|
return NULL;
|
2691
2790
|
}
|
@@ -2980,7 +3079,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
|
|
2980
3079
|
infinite = isinf(flo);
|
2981
3080
|
nan = isnan(flo);
|
2982
3081
|
if (!infinite && !nan) {
|
2983
|
-
vx = GetVpValueWithPrec(x,
|
3082
|
+
vx = GetVpValueWithPrec(x, DBLE_FIG, 0);
|
2984
3083
|
}
|
2985
3084
|
break;
|
2986
3085
|
|
@@ -3133,7 +3232,7 @@ get_vp_value:
|
|
3133
3232
|
infinite = isinf(flo);
|
3134
3233
|
nan = isnan(flo);
|
3135
3234
|
if (!zero && !negative && !infinite && !nan) {
|
3136
|
-
vx = GetVpValueWithPrec(x,
|
3235
|
+
vx = GetVpValueWithPrec(x, DBLE_FIG, 1);
|
3137
3236
|
}
|
3138
3237
|
break;
|
3139
3238
|
|
@@ -3367,7 +3466,7 @@ Init_bigdecimal(void)
|
|
3367
3466
|
rb_define_global_function("BigDecimal", f_BigDecimal, -1);
|
3368
3467
|
|
3369
3468
|
/* Class methods */
|
3370
|
-
|
3469
|
+
rb_undef_alloc_func(rb_cBigDecimal);
|
3371
3470
|
rb_undef_method(CLASS_OF(rb_cBigDecimal), "new");
|
3372
3471
|
rb_define_singleton_method(rb_cBigDecimal, "interpret_loosely", BigDecimal_s_interpret_loosely, 1);
|
3373
3472
|
rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
|
@@ -3501,6 +3600,8 @@ Init_bigdecimal(void)
|
|
3501
3600
|
|
3502
3601
|
/* instance methods */
|
3503
3602
|
rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0);
|
3603
|
+
rb_define_method(rb_cBigDecimal, "precision", BigDecimal_precision, 0);
|
3604
|
+
rb_define_method(rb_cBigDecimal, "n_significant_digits", BigDecimal_n_significant_digits, 0);
|
3504
3605
|
|
3505
3606
|
rb_define_method(rb_cBigDecimal, "add", BigDecimal_add2, 2);
|
3506
3607
|
rb_define_method(rb_cBigDecimal, "sub", BigDecimal_sub2, 2);
|
@@ -4023,7 +4124,7 @@ VpNumOfChars(Real *vp,const char *pszFmt)
|
|
4023
4124
|
* by one BDIGIT word in the computer used.
|
4024
4125
|
*
|
4025
4126
|
* [Returns]
|
4026
|
-
*
|
4127
|
+
* DBLE_FIG ... OK
|
4027
4128
|
*/
|
4028
4129
|
VP_EXPORT size_t
|
4029
4130
|
VpInit(BDIGIT BaseVal)
|
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
@@ -42,6 +42,8 @@ have_func("rb_complex_imag", "ruby.h")
|
|
42
42
|
have_func("rb_array_const_ptr", "ruby.h")
|
43
43
|
have_func("rb_sym2str", "ruby.h")
|
44
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")
|
45
47
|
|
46
48
|
if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__))
|
47
49
|
bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb"
|
data/lib/bigdecimal/util.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-12-
|
13
|
+
date: 2020-12-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.2.2
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Arbitrary-precision decimal floating-point number library.
|