bigdecimal 2.0.0 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fe17cbc3e4c4013708f79a93c975f84b3b55c53028671ef217dde778438a909
4
- data.tar.gz: 5ec9c5839c1ff24a1d08bca8087fff348ec5eaf5aeac910ebb4c972dc00b7b20
3
+ metadata.gz: f755d262f35a249de6848a00e3bf3b8d7a4816dc9a61bb81c099a22baa40bf66
4
+ data.tar.gz: f3b06716476c5da9c8a8006b6aeca492ac0206bce305c23910280fe0a0b28de1
5
5
  SHA512:
6
- metadata.gz: 653b43d52285c5b25dbef5a4ced242d289b966699e099ae37f122a120e924cabd484a534df3d62c1c2e03ae76fefdb874564631bcdd617f041b664b42c34d981
7
- data.tar.gz: 0cc5144ca6df649f27338327021bc7644cd55f7834ff035e473b9abb68d821ea28f9a89f3e6210224547cce0be0c0a56bc9c72d89e63b8446407f2f3ef4ff602
6
+ metadata.gz: 35be1b5d13ee12b4b40ab3cf7277fb235fffcaf554f71107fe3b0727bcef9edb6b03c02bd7db0039505a575752a8014f41402775e8080ec9da2dcda184787df5
7
+ data.tar.gz: f4f063cc6cd0291cbac0f77b2fac485a1e064b08a8789e2ac7b796e6e36529a40a781783bc0417893e01985ad5fa37487c233e5da8fb88eb64c73774de2a9173
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- bigdecimal_version = '2.0.0'
3
+ bigdecimal_version = '2.0.2'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "bigdecimal"
@@ -11,7 +11,7 @@ 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 = "ruby"
14
+ s.license = "Ruby"
15
15
 
16
16
  s.require_paths = %w[lib]
17
17
  s.extensions = %w[ext/bigdecimal/extconf.rb]
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
 
33
33
  s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
34
34
 
35
- s.add_development_dependency "rake", "~> 10.0"
35
+ s.add_development_dependency "rake", ">= 12.3.3"
36
36
  s.add_development_dependency "rake-compiler", ">= 0.9"
37
37
  s.add_development_dependency "minitest", "< 5.0.0"
38
38
  s.add_development_dependency "pry"
@@ -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>
@@ -367,8 +367,8 @@ BigDecimal_prec(VALUE self)
367
367
  VALUE obj;
368
368
 
369
369
  GUARD_OBJ(p, GetVpValue(self, 1));
370
- obj = rb_assoc_new(INT2NUM(p->Prec*VpBaseFig()),
371
- INT2NUM(p->MaxPrec*VpBaseFig()));
370
+ obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()),
371
+ SIZET2NUM(p->MaxPrec*VpBaseFig()));
372
372
  return obj;
373
373
  }
374
374
 
@@ -1791,10 +1791,10 @@ BigDecimal_fix(VALUE self)
1791
1791
  * more than that many digits.
1792
1792
  *
1793
1793
  * If n is specified and negative, at least that many digits to the left of the
1794
- * decimal point will be 0 in the result.
1794
+ * decimal point will be 0 in the result, and return value will be an Integer.
1795
1795
  *
1796
1796
  * BigDecimal('3.14159').round(3) #=> 3.142
1797
- * BigDecimal('13345.234').round(-2) #=> 13300.0
1797
+ * BigDecimal('13345.234').round(-2) #=> 13300
1798
1798
  *
1799
1799
  * The value of the optional mode argument can be used to determine how
1800
1800
  * rounding is performed; see BigDecimal.mode.
@@ -1807,6 +1807,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1807
1807
  int iLoc = 0;
1808
1808
  VALUE vLoc;
1809
1809
  VALUE vRound;
1810
+ int round_to_int = 0;
1810
1811
  size_t mx, pl;
1811
1812
 
1812
1813
  unsigned short sw = VpGetRoundMode();
@@ -1814,6 +1815,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1814
1815
  switch (rb_scan_args(argc, argv, "02", &vLoc, &vRound)) {
1815
1816
  case 0:
1816
1817
  iLoc = 0;
1818
+ round_to_int = 1;
1817
1819
  break;
1818
1820
  case 1:
1819
1821
  if (RB_TYPE_P(vLoc, T_HASH)) {
@@ -1821,6 +1823,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1821
1823
  }
1822
1824
  else {
1823
1825
  iLoc = NUM2INT(vLoc);
1826
+ if (iLoc < 1) round_to_int = 1;
1824
1827
  }
1825
1828
  break;
1826
1829
  case 2:
@@ -1842,7 +1845,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1842
1845
  GUARD_OBJ(c, VpCreateRbObject(mx, "0"));
1843
1846
  VpSetPrecLimit(pl);
1844
1847
  VpActiveRound(c, a, sw, iLoc);
1845
- if (argc == 0) {
1848
+ if (round_to_int) {
1846
1849
  return BigDecimal_to_i(ToValue(c));
1847
1850
  }
1848
1851
  return ToValue(c);
@@ -2091,7 +2094,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
2091
2094
  nc += (nc + mc - 1) / mc + 1;
2092
2095
  }
2093
2096
 
2094
- str = rb_str_new(0, nc);
2097
+ str = rb_usascii_str_new(0, nc);
2095
2098
  psz = RSTRING_PTR(str);
2096
2099
 
2097
2100
  if (fmt) {
@@ -2156,7 +2159,7 @@ BigDecimal_split(VALUE self)
2156
2159
  rb_ary_push(obj, str);
2157
2160
  rb_str_resize(str, strlen(psz1));
2158
2161
  rb_ary_push(obj, INT2FIX(10));
2159
- rb_ary_push(obj, INT2NUM(e));
2162
+ rb_ary_push(obj, SSIZET2NUM(e));
2160
2163
  return obj;
2161
2164
  }
2162
2165
 
@@ -2169,7 +2172,7 @@ static VALUE
2169
2172
  BigDecimal_exponent(VALUE self)
2170
2173
  {
2171
2174
  ssize_t e = VpExponent10(GetVpValue(self, 1));
2172
- return INT2NUM(e);
2175
+ return SSIZET2NUM(e);
2173
2176
  }
2174
2177
 
2175
2178
  /* Returns a string representation of self.
@@ -2362,7 +2365,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
2362
2365
  }
2363
2366
  goto retry;
2364
2367
  }
2365
- exp = GetVpValueWithPrec(vexp, DBL_DIG+1, 1);
2368
+ if (NIL_P(prec)) {
2369
+ n += DBLE_FIG;
2370
+ }
2371
+ exp = GetVpValueWithPrec(vexp, DBLE_FIG, 1);
2366
2372
  break;
2367
2373
 
2368
2374
  case T_RATIONAL:
@@ -2377,6 +2383,9 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
2377
2383
  goto retry;
2378
2384
  }
2379
2385
  exp = GetVpValueWithPrec(vexp, n, 1);
2386
+ if (NIL_P(prec)) {
2387
+ n += n;
2388
+ }
2380
2389
  break;
2381
2390
 
2382
2391
  case T_DATA:
@@ -2387,6 +2396,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
2387
2396
  vexp = BigDecimal_to_i(vexp);
2388
2397
  goto retry;
2389
2398
  }
2399
+ if (NIL_P(prec)) {
2400
+ GUARD_OBJ(y, GetVpValue(vexp, 1));
2401
+ n += y->Prec*VpBaseFig();
2402
+ }
2390
2403
  exp = DATA_PTR(vexp);
2391
2404
  break;
2392
2405
  }
@@ -2802,7 +2815,7 @@ static VALUE
2802
2815
  BigDecimal_limit(int argc, VALUE *argv, VALUE self)
2803
2816
  {
2804
2817
  VALUE nFig;
2805
- VALUE nCur = INT2NUM(VpGetPrecLimit());
2818
+ VALUE nCur = SIZET2NUM(VpGetPrecLimit());
2806
2819
 
2807
2820
  if (rb_scan_args(argc, argv, "01", &nFig) == 1) {
2808
2821
  int nf;
@@ -4180,7 +4193,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
4180
4193
  /* at least mx digits. */
4181
4194
  /* szVal==NULL ==> allocate zero value. */
4182
4195
  vp = VpAllocReal(mx);
4183
- /* xmalloc() alway returns(or throw interruption) */
4196
+ /* xmalloc() always returns(or throw interruption) */
4184
4197
  vp->MaxPrec = mx; /* set max precision */
4185
4198
  VpSetZero(vp, 1); /* initialize vp to zero. */
4186
4199
  return vp;
@@ -4356,7 +4369,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
4356
4369
  nalloc = Max(nalloc, mx);
4357
4370
  mx = nalloc;
4358
4371
  vp = VpAllocReal(mx);
4359
- /* xmalloc() alway returns(or throw interruption) */
4372
+ /* xmalloc() always returns(or throw interruption) */
4360
4373
  vp->MaxPrec = mx; /* set max precision */
4361
4374
  VpSetZero(vp, sign);
4362
4375
  VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne);
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.0
4
+ version: 2.0.2
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: 2019-12-26 00:00:00.000000000 Z
13
+ date: 2020-12-15 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: '10.0'
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: '10.0'
28
+ version: 12.3.3
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake-compiler
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +92,7 @@ files:
92
92
  - sample/pi.rb
93
93
  homepage: https://github.com/ruby/bigdecimal
94
94
  licenses:
95
- - ruby
95
+ - Ruby
96
96
  metadata: {}
97
97
  post_install_message:
98
98
  rdoc_options: []
@@ -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.0.3
112
+ rubygems_version: 3.1.4
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Arbitrary-precision decimal floating-point number library.