bigdecimal 3.1.7 → 3.1.9
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 +2 -0
- data/ext/bigdecimal/bigdecimal.c +85 -33
- data/ext/bigdecimal/extconf.rb +11 -9
- data/ext/bigdecimal/missing.c +2 -1
- data/lib/bigdecimal/util.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61cbb7233c53f76dca23b078090706faa4c5796f983d9b0bf207bb2d6c652625
|
4
|
+
data.tar.gz: d7f68a343595d21e009f43ac47558d1805e004cefb85e6d0d423e46b307ba9fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b091bed99353940b359a3d4ba6639f67cfad6859efda3709007aec5310539c0159d333ee5fb425cdecde146d2bd4241b6e208ee273cde337f449d467a7593e4
|
7
|
+
data.tar.gz: 0fa14bd118018db4d4b436375f804d62e6c894458a3fa555cafc2c8da2888bd03dea8206e3ce15a73f82b35afcd6c8285881d2c76acb14e9013cf1e72f7284c3
|
data/bigdecimal.gemspec
CHANGED
data/ext/bigdecimal/bigdecimal.c
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
#include "bits.h"
|
32
32
|
#include "static_assert.h"
|
33
33
|
|
34
|
-
#define BIGDECIMAL_VERSION "3.1.
|
34
|
+
#define BIGDECIMAL_VERSION "3.1.9"
|
35
35
|
|
36
36
|
/* #define ENABLE_NUMERIC_STRING */
|
37
37
|
|
@@ -1780,6 +1780,17 @@ BigDecimal_neg(VALUE self)
|
|
1780
1780
|
return VpCheckGetValue(c);
|
1781
1781
|
}
|
1782
1782
|
|
1783
|
+
/*
|
1784
|
+
* call-seq:
|
1785
|
+
* a * b -> bigdecimal
|
1786
|
+
*
|
1787
|
+
* Multiply by the specified value.
|
1788
|
+
*
|
1789
|
+
* The result precision will be the precision of the sum of each precision.
|
1790
|
+
*
|
1791
|
+
* See BigDecimal#mult.
|
1792
|
+
*/
|
1793
|
+
|
1783
1794
|
static VALUE
|
1784
1795
|
BigDecimal_mult(VALUE self, VALUE r)
|
1785
1796
|
{
|
@@ -2448,7 +2459,7 @@ BigDecimal_fix(VALUE self)
|
|
2448
2459
|
* round(n, mode)
|
2449
2460
|
*
|
2450
2461
|
* Round to the nearest integer (by default), returning the result as a
|
2451
|
-
* BigDecimal if n is specified, or as an Integer if it isn't.
|
2462
|
+
* BigDecimal if n is specified and positive, or as an Integer if it isn't.
|
2452
2463
|
*
|
2453
2464
|
* BigDecimal('3.14159').round #=> 3
|
2454
2465
|
* BigDecimal('8.7').round #=> 9
|
@@ -2456,6 +2467,7 @@ BigDecimal_fix(VALUE self)
|
|
2456
2467
|
*
|
2457
2468
|
* BigDecimal('3.14159').round(2).class.name #=> "BigDecimal"
|
2458
2469
|
* BigDecimal('3.14159').round.class.name #=> "Integer"
|
2470
|
+
* BigDecimal('3.14159').round(0).class.name #=> "Integer"
|
2459
2471
|
*
|
2460
2472
|
* If n is specified and positive, the fractional part of the result has no
|
2461
2473
|
* more than that many digits.
|
@@ -3257,10 +3269,11 @@ BigDecimal_initialize_copy(VALUE self, VALUE other)
|
|
3257
3269
|
return self;
|
3258
3270
|
}
|
3259
3271
|
|
3272
|
+
/* :nodoc: */
|
3260
3273
|
static VALUE
|
3261
3274
|
BigDecimal_clone(VALUE self)
|
3262
3275
|
{
|
3263
|
-
|
3276
|
+
return self;
|
3264
3277
|
}
|
3265
3278
|
|
3266
3279
|
#ifdef HAVE_RB_OPTS_EXCEPTION_P
|
@@ -3758,6 +3771,12 @@ f_BigDecimal(int argc, VALUE *argv, VALUE self)
|
|
3758
3771
|
return rb_convert_to_BigDecimal(val, digs, exception);
|
3759
3772
|
}
|
3760
3773
|
|
3774
|
+
/* call-seq:
|
3775
|
+
* BigDecimal.interpret_loosely(string) -> bigdecimal
|
3776
|
+
*
|
3777
|
+
* Returns the +BigDecimal+ converted loosely from +string+.
|
3778
|
+
*/
|
3779
|
+
|
3761
3780
|
static VALUE
|
3762
3781
|
BigDecimal_s_interpret_loosely(VALUE klass, VALUE str)
|
3763
3782
|
{
|
@@ -4238,6 +4257,17 @@ BigDecimal_negative_zero(void)
|
|
4238
4257
|
return BIGDECIMAL_NEGATIVE_ZERO;
|
4239
4258
|
}
|
4240
4259
|
|
4260
|
+
static inline VALUE
|
4261
|
+
BigDecimal_literal(const char *str)
|
4262
|
+
{
|
4263
|
+
VALUE arg = rb_str_new_cstr(str);
|
4264
|
+
VALUE val = f_BigDecimal(1, &arg, rb_cBigDecimal);
|
4265
|
+
rb_gc_register_mark_object(val);
|
4266
|
+
return val;
|
4267
|
+
}
|
4268
|
+
|
4269
|
+
#define BIGDECIMAL_LITERAL(var, val) (BIGDECIMAL_ ## var = BigDecimal_literal(#val))
|
4270
|
+
|
4241
4271
|
/* Document-class: BigDecimal
|
4242
4272
|
* BigDecimal provides arbitrary-precision floating point decimal arithmetic.
|
4243
4273
|
*
|
@@ -4394,7 +4424,6 @@ Init_bigdecimal(void)
|
|
4394
4424
|
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
4395
4425
|
rb_ext_ractor_safe(true);
|
4396
4426
|
#endif
|
4397
|
-
VALUE arg;
|
4398
4427
|
|
4399
4428
|
id_BigDecimal_exception_mode = rb_intern_const("BigDecimal.exception_mode");
|
4400
4429
|
id_BigDecimal_rounding_mode = rb_intern_const("BigDecimal.rounding_mode");
|
@@ -4532,33 +4561,19 @@ Init_bigdecimal(void)
|
|
4532
4561
|
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_INFINITE", INT2FIX(VP_SIGN_NEGATIVE_INFINITE));
|
4533
4562
|
|
4534
4563
|
/* Positive zero value. */
|
4535
|
-
|
4536
|
-
BIGDECIMAL_POSITIVE_ZERO = f_BigDecimal(1, &arg, rb_cBigDecimal);
|
4537
|
-
rb_gc_register_mark_object(BIGDECIMAL_POSITIVE_ZERO);
|
4564
|
+
BIGDECIMAL_LITERAL(POSITIVE_ZERO, +0);
|
4538
4565
|
|
4539
4566
|
/* Negative zero value. */
|
4540
|
-
|
4541
|
-
BIGDECIMAL_NEGATIVE_ZERO = f_BigDecimal(1, &arg, rb_cBigDecimal);
|
4542
|
-
rb_gc_register_mark_object(BIGDECIMAL_NEGATIVE_ZERO);
|
4567
|
+
BIGDECIMAL_LITERAL(NEGATIVE_ZERO, -0);
|
4543
4568
|
|
4544
|
-
/* Positive infinity value. */
|
4545
|
-
|
4546
|
-
BIGDECIMAL_POSITIVE_INFINITY = f_BigDecimal(1, &arg, rb_cBigDecimal);
|
4547
|
-
rb_gc_register_mark_object(BIGDECIMAL_POSITIVE_INFINITY);
|
4569
|
+
/* Positive infinity[rdoc-ref:BigDecimal@Infinity] value. */
|
4570
|
+
rb_define_const(rb_cBigDecimal, "INFINITY", BIGDECIMAL_LITERAL(POSITIVE_INFINITY, +Infinity));
|
4548
4571
|
|
4549
4572
|
/* Negative infinity value. */
|
4550
|
-
|
4551
|
-
BIGDECIMAL_NEGATIVE_INFINITY = f_BigDecimal(1, &arg, rb_cBigDecimal);
|
4552
|
-
rb_gc_register_mark_object(BIGDECIMAL_NEGATIVE_INFINITY);
|
4573
|
+
BIGDECIMAL_LITERAL(NEGATIVE_INFINITY, -Infinity);
|
4553
4574
|
|
4554
|
-
/* 'Not a Number' value. */
|
4555
|
-
|
4556
|
-
BIGDECIMAL_NAN = f_BigDecimal(1, &arg, rb_cBigDecimal);
|
4557
|
-
rb_gc_register_mark_object(BIGDECIMAL_NAN);
|
4558
|
-
|
4559
|
-
/* Special value constants */
|
4560
|
-
rb_define_const(rb_cBigDecimal, "INFINITY", BIGDECIMAL_POSITIVE_INFINITY);
|
4561
|
-
rb_define_const(rb_cBigDecimal, "NAN", BIGDECIMAL_NAN);
|
4575
|
+
/* '{Not a Number}[rdoc-ref:BigDecimal@Not+a+Number]' value. */
|
4576
|
+
rb_define_const(rb_cBigDecimal, "NAN", BIGDECIMAL_LITERAL(NAN, NaN));
|
4562
4577
|
|
4563
4578
|
/* instance methods */
|
4564
4579
|
rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0);
|
@@ -5203,6 +5218,48 @@ bigdecimal_parse_special_string(const char *str)
|
|
5203
5218
|
return NULL;
|
5204
5219
|
}
|
5205
5220
|
|
5221
|
+
struct VpCtoV_args {
|
5222
|
+
Real *a;
|
5223
|
+
const char *int_chr;
|
5224
|
+
size_t ni;
|
5225
|
+
const char *frac;
|
5226
|
+
size_t nf;
|
5227
|
+
const char *exp_chr;
|
5228
|
+
size_t ne;
|
5229
|
+
};
|
5230
|
+
|
5231
|
+
static VALUE
|
5232
|
+
call_VpCtoV(VALUE arg)
|
5233
|
+
{
|
5234
|
+
struct VpCtoV_args *x = (struct VpCtoV_args *)arg;
|
5235
|
+
return (VALUE)VpCtoV(x->a, x->int_chr, x->ni, x->frac, x->nf, x->exp_chr, x->ne);
|
5236
|
+
}
|
5237
|
+
|
5238
|
+
static int
|
5239
|
+
protected_VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, const char *exp_chr, size_t ne, int free_on_error)
|
5240
|
+
{
|
5241
|
+
struct VpCtoV_args args;
|
5242
|
+
int state = 0;
|
5243
|
+
|
5244
|
+
args.a = a;
|
5245
|
+
args.int_chr = int_chr;
|
5246
|
+
args.ni = ni;
|
5247
|
+
args.frac = frac;
|
5248
|
+
args.nf = nf;
|
5249
|
+
args.exp_chr = exp_chr;
|
5250
|
+
args.ne = ne;
|
5251
|
+
|
5252
|
+
VALUE result = rb_protect(call_VpCtoV, (VALUE)&args, &state);
|
5253
|
+
if (state) {
|
5254
|
+
if (free_on_error) {
|
5255
|
+
rbd_free_struct(a);
|
5256
|
+
}
|
5257
|
+
rb_jump_tag(state);
|
5258
|
+
}
|
5259
|
+
|
5260
|
+
return (int)result;
|
5261
|
+
}
|
5262
|
+
|
5206
5263
|
/*
|
5207
5264
|
* Allocates variable.
|
5208
5265
|
* [Input]
|
@@ -5220,7 +5277,7 @@ VP_EXPORT Real *
|
|
5220
5277
|
VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
5221
5278
|
{
|
5222
5279
|
const char *orig_szVal = szVal;
|
5223
|
-
size_t i, j, ni, ipf, nf, ipe, ne,
|
5280
|
+
size_t i, j, ni, ipf, nf, ipe, ne, exp_seen, nalloc;
|
5224
5281
|
size_t len;
|
5225
5282
|
char v, *psz;
|
5226
5283
|
int sign=1;
|
@@ -5306,13 +5363,11 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
5306
5363
|
ne = 0; /* number of digits in the exponential part */
|
5307
5364
|
ipf = 0; /* index of the beginning of the fractional part */
|
5308
5365
|
ipe = 0; /* index of the beginning of the exponential part */
|
5309
|
-
dot_seen = 0;
|
5310
5366
|
exp_seen = 0;
|
5311
5367
|
|
5312
5368
|
if (v != '\0') {
|
5313
5369
|
/* Scanning fractional part */
|
5314
5370
|
if ((psz[i] = szVal[j]) == '.') {
|
5315
|
-
dot_seen = 1;
|
5316
5371
|
++i;
|
5317
5372
|
++j;
|
5318
5373
|
ipf = i;
|
@@ -5328,9 +5383,6 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
5328
5383
|
}
|
5329
5384
|
if (!strict_p) {
|
5330
5385
|
v = psz[i] = '\0';
|
5331
|
-
if (nf == 0) {
|
5332
|
-
dot_seen = 0;
|
5333
|
-
}
|
5334
5386
|
break;
|
5335
5387
|
}
|
5336
5388
|
goto invalid_value;
|
@@ -5401,7 +5453,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
5401
5453
|
|
5402
5454
|
psz[i] = '\0';
|
5403
5455
|
|
5404
|
-
if (strict_p && ((
|
5456
|
+
if (strict_p && ((ni == 0 && nf == 0) || (exp_seen && ne == 0))) {
|
5405
5457
|
VALUE str;
|
5406
5458
|
invalid_value:
|
5407
5459
|
if (!strict_p) {
|
@@ -5422,7 +5474,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
|
|
5422
5474
|
vp = rbd_allocate_struct(len);
|
5423
5475
|
vp->MaxPrec = len; /* set max precision */
|
5424
5476
|
VpSetZero(vp, sign);
|
5425
|
-
|
5477
|
+
protected_VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne, true);
|
5426
5478
|
rb_str_resize(buf, 0);
|
5427
5479
|
return vp;
|
5428
5480
|
}
|
data/ext/bigdecimal/extconf.rb
CHANGED
@@ -24,15 +24,17 @@ have_header("math.h")
|
|
24
24
|
have_header("stdbool.h")
|
25
25
|
have_header("stdlib.h")
|
26
26
|
|
27
|
-
have_header("x86intrin.h")
|
28
|
-
have_func("_lzcnt_u32", "x86intrin.h")
|
29
|
-
have_func("_lzcnt_u64", "x86intrin.h")
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
have_func("
|
34
|
-
have_func("
|
35
|
-
have_func("
|
27
|
+
if have_header("x86intrin.h")
|
28
|
+
have_func("_lzcnt_u32", "x86intrin.h")
|
29
|
+
have_func("_lzcnt_u64", "x86intrin.h")
|
30
|
+
end
|
31
|
+
|
32
|
+
if have_header("intrin.h")
|
33
|
+
have_func("__lzcnt", "intrin.h")
|
34
|
+
have_func("__lzcnt64", "intrin.h")
|
35
|
+
have_func("_BitScanReverse", "intrin.h")
|
36
|
+
have_func("_BitScanReverse64", "intrin.h")
|
37
|
+
end
|
36
38
|
|
37
39
|
have_func("labs", "stdlib.h")
|
38
40
|
have_func("llabs", "stdlib.h")
|
data/ext/bigdecimal/missing.c
CHANGED
data/lib/bigdecimal/util.rb
CHANGED
@@ -155,7 +155,7 @@ class Complex < Numeric
|
|
155
155
|
# See also Kernel.BigDecimal.
|
156
156
|
#
|
157
157
|
def to_d(*args)
|
158
|
-
BigDecimal(self) unless self.imag.zero? # to raise
|
158
|
+
BigDecimal(self) unless self.imag.zero? # to raise error
|
159
159
|
|
160
160
|
if args.length == 0
|
161
161
|
case self.real
|
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: 3.1.
|
4
|
+
version: 3.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Shigeo Kobayashi
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This library provides arbitrary-precision decimal floating-point number
|
15
15
|
class.
|
@@ -44,7 +44,8 @@ homepage: https://github.com/ruby/bigdecimal
|
|
44
44
|
licenses:
|
45
45
|
- Ruby
|
46
46
|
- BSD-2-Clause
|
47
|
-
metadata:
|
47
|
+
metadata:
|
48
|
+
changelog_uri: https://github.com/ruby/bigdecimal/blob/master/CHANGES.md
|
48
49
|
rdoc_options: []
|
49
50
|
require_paths:
|
50
51
|
- lib
|
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
62
|
requirements: []
|
62
|
-
rubygems_version: 3.6.
|
63
|
+
rubygems_version: 3.6.2
|
63
64
|
specification_version: 4
|
64
65
|
summary: Arbitrary-precision decimal floating-point number library.
|
65
66
|
test_files: []
|