bigdecimal 3.1.4 → 3.1.5

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: 4107ae2a3ed84ad02b56f2f57c31087185545454e53089e8176a23bd829c5177
4
- data.tar.gz: 392489743d1863336597fc19039c1fd0077c5735b096de799f8adf61a5c29dbe
3
+ metadata.gz: 109c70397447eabf22f0e869db4b2c0c902c7d0baaf28865aebfc534e3c14b9f
4
+ data.tar.gz: 43df8b8d27be2b5cbf29c7396c07eabbca3119067b525f94155f2901f2c058d4
5
5
  SHA512:
6
- metadata.gz: 337fb13844251d627cecd341da3bc0a23b0addcc0b83f49f76e3fc0796852e24d71291712b270c79e3cb9e729bd2d831e4ca303a46dd4c7446404de6175b1f86
7
- data.tar.gz: 4d2b9734294ff4f154df4012bd8f21964e3627b29ade7c716079ad6a74c19713a0a0a287cb57315d642cac7fe9b521db21104e9ea89eef745babcf292b7a67d2
6
+ metadata.gz: 8b0b82714e555c1ca30e761296f497d2cf914a50d19d553cca37b51af6b85914bbc86772b5bb8d70388020dbff9abc3e0501b3d6bb95ba3d68c30a91d5b197fa
7
+ data.tar.gz: a4bc1e9d1918fb84f5405c3dc2fce2358a074f0f729084936ec7ee2010dffeeee889fb0054d932f35175c48577888fc74bba7afde492f628d8beef5deeeadc0d
@@ -31,7 +31,7 @@
31
31
  #include "bits.h"
32
32
  #include "static_assert.h"
33
33
 
34
- #define BIGDECIMAL_VERSION "3.1.4"
34
+ #define BIGDECIMAL_VERSION "3.1.5"
35
35
 
36
36
  /* #define ENABLE_NUMERIC_STRING */
37
37
 
@@ -657,7 +657,7 @@ BigDecimal_precision(VALUE self)
657
657
  * Returns the number of decimal digits following the decimal digits in +self+.
658
658
  *
659
659
  * BigDecimal("0").scale # => 0
660
- * BigDecimal("1").scale # => 1
660
+ * BigDecimal("1").scale # => 0
661
661
  * BigDecimal("1.1").scale # => 1
662
662
  * BigDecimal("3.1415").scale # => 4
663
663
  * BigDecimal("-1e20").precision # => 0
@@ -2689,7 +2689,7 @@ BigDecimal_ceil(int argc, VALUE *argv, VALUE self)
2689
2689
  * A space at the start of s returns positive values with a leading space.
2690
2690
  *
2691
2691
  * If s contains a number, a space is inserted after each group of that many
2692
- * fractional digits.
2692
+ * digits, starting from '.' and counting outwards.
2693
2693
  *
2694
2694
  * If s ends with an 'E', engineering notation (0.xxxxEnn) is used.
2695
2695
  *
@@ -2697,14 +2697,14 @@ BigDecimal_ceil(int argc, VALUE *argv, VALUE self)
2697
2697
  *
2698
2698
  * Examples:
2699
2699
  *
2700
- * BigDecimal('-123.45678901234567890').to_s('5F')
2701
- * #=> '-123.45678 90123 45678 9'
2700
+ * BigDecimal('-1234567890123.45678901234567890').to_s('5F')
2701
+ * #=> '-123 45678 90123.45678 90123 45678 9'
2702
2702
  *
2703
- * BigDecimal('123.45678901234567890').to_s('+8F')
2704
- * #=> '+123.45678901 23456789'
2703
+ * BigDecimal('1234567890123.45678901234567890').to_s('+8F')
2704
+ * #=> '+12345 67890123.45678901 23456789'
2705
2705
  *
2706
- * BigDecimal('123.45678901234567890').to_s(' F')
2707
- * #=> ' 123.4567890123456789'
2706
+ * BigDecimal('1234567890123.45678901234567890').to_s(' F')
2707
+ * #=> ' 1234567890123.4567890123456789'
2708
2708
  */
2709
2709
  static VALUE
2710
2710
  BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
@@ -3722,7 +3722,7 @@ rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
3722
3722
  * - Other type:
3723
3723
  *
3724
3724
  * - Raises an exception if keyword argument +exception+ is +true+.
3725
- * - Returns +nil+ if keyword argument +exception+ is +true+.
3725
+ * - Returns +nil+ if keyword argument +exception+ is +false+.
3726
3726
  *
3727
3727
  * Raises an exception if +value+ evaluates to a Float
3728
3728
  * and +digits+ is larger than Float::DIG + 1.
@@ -4363,7 +4363,20 @@ BigDecimal_negative_zero(void)
4363
4363
  * (2/3r).to_d(3) # => 0.667e0
4364
4364
  * "0.5".to_d # => 0.5e0
4365
4365
  *
4366
- * == License
4366
+ * == Methods for Working with \JSON
4367
+ *
4368
+ * - {::json_create}[https://docs.ruby-lang.org/en/master/BigDecimal.html#method-c-json_create]:
4369
+ * Returns a new \BigDecimal object constructed from the given object.
4370
+ * - {#as_json}[https://docs.ruby-lang.org/en/master/BigDecimal.html#method-i-as_json]:
4371
+ * Returns a 2-element hash representing +self+.
4372
+ * - {#to_json}[https://docs.ruby-lang.org/en/master/BigDecimal.html#method-i-to_json]:
4373
+ * Returns a \JSON string representing +self+.
4374
+ *
4375
+ * These methods are provided by the {JSON gem}[https://github.com/flori/json]. To make these methods available:
4376
+ *
4377
+ * require 'json/add/bigdecimal'
4378
+ *
4379
+ * * == License
4367
4380
  *
4368
4381
  * Copyright (C) 2002 by Shigeo Kobayashi <shigeo@tinyforest.gr.jp>.
4369
4382
  *
@@ -6706,95 +6719,90 @@ VpToFString(Real *a, char *buf, size_t buflen, size_t fFmt, int fPlus)
6706
6719
  /* fPlus = 0: default, 1: set ' ' before digits, 2: set '+' before digits. */
6707
6720
  {
6708
6721
  size_t i, n;
6709
- DECDIG m, e, nn;
6722
+ DECDIG m, e;
6710
6723
  char *p = buf;
6711
- size_t plen = buflen;
6724
+ size_t plen = buflen, delim = fFmt;
6712
6725
  ssize_t ex;
6713
6726
 
6714
6727
  if (VpToSpecialString(a, buf, buflen, fPlus)) return;
6715
6728
 
6716
- #define ADVANCE(n) do { \
6717
- if (plen < n) goto overflow; \
6718
- p += n; \
6719
- plen -= n; \
6729
+ #define APPEND(c, group) do { \
6730
+ if (plen < 1) goto overflow; \
6731
+ if (group && delim == 0) { \
6732
+ *p = ' '; \
6733
+ p += 1; \
6734
+ plen -= 1; \
6735
+ } \
6736
+ if (plen < 1) goto overflow; \
6737
+ *p = c; \
6738
+ p += 1; \
6739
+ plen -= 1; \
6740
+ if (group) delim = (delim + 1) % fFmt; \
6720
6741
  } while (0)
6721
6742
 
6722
6743
 
6723
6744
  if (BIGDECIMAL_NEGATIVE_P(a)) {
6724
- *p = '-';
6725
- ADVANCE(1);
6745
+ APPEND('-', false);
6726
6746
  }
6727
6747
  else if (fPlus == 1) {
6728
- *p = ' ';
6729
- ADVANCE(1);
6748
+ APPEND(' ', false);
6730
6749
  }
6731
6750
  else if (fPlus == 2) {
6732
- *p = '+';
6733
- ADVANCE(1);
6751
+ APPEND('+', false);
6734
6752
  }
6735
6753
 
6736
6754
  n = a->Prec;
6737
6755
  ex = a->exponent;
6738
6756
  if (ex <= 0) {
6739
- *p = '0'; ADVANCE(1);
6740
- *p = '.'; ADVANCE(1);
6741
- while (ex < 0) {
6742
- for (i=0; i < BASE_FIG; ++i) {
6743
- *p = '0'; ADVANCE(1);
6744
- }
6745
- ++ex;
6757
+ APPEND('0', false);
6758
+ APPEND('.', false);
6759
+ }
6760
+ while (ex < 0) {
6761
+ for (i=0; i < BASE_FIG; ++i) {
6762
+ APPEND('0', fFmt > 0);
6746
6763
  }
6747
- ex = -1;
6764
+ ++ex;
6748
6765
  }
6749
6766
 
6750
6767
  for (i = 0; i < n; ++i) {
6751
- --ex;
6752
- if (i == 0 && ex >= 0) {
6753
- size_t n = snprintf(p, plen, "%lu", (unsigned long)a->frac[i]);
6754
- if (n > plen) goto overflow;
6755
- ADVANCE(n);
6756
- }
6757
- else {
6758
- m = BASE1;
6759
- e = a->frac[i];
6760
- while (m) {
6761
- nn = e / m;
6762
- *p = (char)(nn + '0');
6763
- ADVANCE(1);
6764
- e = e - nn * m;
6768
+ m = BASE1;
6769
+ e = a->frac[i];
6770
+ if (i == 0 && ex > 0) {
6771
+ for (delim = 0; e / m == 0; delim++) {
6765
6772
  m /= 10;
6766
6773
  }
6774
+ if (fFmt > 0) {
6775
+ delim = 2*fFmt - (ex * BASE_FIG - delim) % fFmt;
6776
+ }
6777
+ }
6778
+ while (m && (e || (i < n - 1) || ex > 0)) {
6779
+ APPEND((char)(e / m + '0'), fFmt > 0);
6780
+ e %= m;
6781
+ m /= 10;
6767
6782
  }
6768
- if (ex == 0) {
6769
- *p = '.';
6770
- ADVANCE(1);
6783
+ if (--ex == 0) {
6784
+ APPEND('.', false);
6785
+ delim = fFmt;
6771
6786
  }
6772
6787
  }
6773
- while (--ex>=0) {
6774
- m = BASE;
6775
- while (m /= 10) {
6776
- *p = '0';
6777
- ADVANCE(1);
6788
+
6789
+ while (ex > 0) {
6790
+ for (i=0; i < BASE_FIG; ++i) {
6791
+ APPEND('0', fFmt > 0);
6778
6792
  }
6779
- if (ex == 0) {
6780
- *p = '.';
6781
- ADVANCE(1);
6793
+ if (--ex == 0) {
6794
+ APPEND('.', false);
6782
6795
  }
6783
6796
  }
6784
6797
 
6785
6798
  *p = '\0';
6786
- while (p - 1 > buf && p[-1] == '0') {
6787
- *(--p) = '\0';
6788
- ++plen;
6789
- }
6790
6799
  if (p - 1 > buf && p[-1] == '.') {
6791
6800
  snprintf(p, plen, "0");
6792
6801
  }
6793
- if (fFmt) VpFormatSt(buf, fFmt);
6794
6802
 
6795
6803
  overflow:
6796
6804
  return;
6797
- #undef ADVANCE
6805
+ #undef APPEND
6798
6806
  }
6799
6807
 
6800
6808
  /*
@@ -7171,7 +7179,6 @@ VpSqrt(Real *y, Real *x)
7171
7179
  Real *r = NULL;
7172
7180
  size_t y_prec;
7173
7181
  SIGNED_VALUE n, e;
7174
- SIGNED_VALUE prec;
7175
7182
  ssize_t nr;
7176
7183
  double val;
7177
7184
 
@@ -7210,12 +7217,6 @@ VpSqrt(Real *y, Real *x)
7210
7217
  nr = 0;
7211
7218
  y_prec = y->MaxPrec;
7212
7219
 
7213
- prec = x->exponent - (ssize_t)y_prec;
7214
- if (x->exponent > 0)
7215
- ++prec;
7216
- else
7217
- --prec;
7218
-
7219
7220
  VpVtoD(&val, &e, x); /* val <- x */
7220
7221
  e /= (SIGNED_VALUE)BASE_FIG;
7221
7222
  n = e / 2;
@@ -18,7 +18,7 @@ class Integer < Numeric
18
18
  #
19
19
  # 42.to_d # => 0.42e2
20
20
  #
21
- # See also BigDecimal::new.
21
+ # See also Kernel.BigDecimal.
22
22
  #
23
23
  def to_d
24
24
  BigDecimal(self)
@@ -45,7 +45,7 @@ class Float < Numeric
45
45
  # 1.234.to_d # => 0.1234e1
46
46
  # 1.234.to_d(2) # => 0.12e1
47
47
  #
48
- # See also BigDecimal::new.
48
+ # See also Kernel.BigDecimal.
49
49
  #
50
50
  def to_d(precision=0)
51
51
  BigDecimal(self, precision)
@@ -67,7 +67,7 @@ class String
67
67
  # "123.45e1".to_d # => 0.12345e4
68
68
  # "45.67 degrees".to_d # => 0.4567e2
69
69
  #
70
- # See also BigDecimal::new.
70
+ # See also Kernel.BigDecimal.
71
71
  #
72
72
  def to_d
73
73
  BigDecimal.interpret_loosely(self)
@@ -127,7 +127,7 @@ class Rational < Numeric
127
127
  #
128
128
  # Rational(22, 7).to_d(3) # => 0.314e1
129
129
  #
130
- # See also BigDecimal::new.
130
+ # See also Kernel.BigDecimal.
131
131
  #
132
132
  def to_d(precision)
133
133
  BigDecimal(self, precision)
@@ -152,7 +152,7 @@ class Complex < Numeric
152
152
  # Complex(0.1234567, 0).to_d(4) # => 0.1235e0
153
153
  # Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
154
154
  #
155
- # See also BigDecimal::new.
155
+ # See also Kernel.BigDecimal.
156
156
  #
157
157
  def to_d(*args)
158
158
  BigDecimal(self) unless self.imag.zero? # to raise eerror
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigdecimal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Murata
8
8
  - Zachary Scott
9
9
  - Shigeo Kobayashi
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-03-07 00:00:00.000000000 Z
13
+ date: 2023-12-13 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: This library provides arbitrary-precision decimal floating-point number
16
16
  class.
@@ -45,7 +45,7 @@ licenses:
45
45
  - Ruby
46
46
  - BSD-2-Clause
47
47
  metadata: {}
48
- post_install_message:
48
+ post_install_message:
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
@@ -60,8 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.3.13
64
- signing_key:
63
+ rubygems_version: 3.3.9
64
+ signing_key:
65
65
  specification_version: 4
66
66
  summary: Arbitrary-precision decimal floating-point number library.
67
67
  test_files: []