bigdecimal 3.1.4 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4107ae2a3ed84ad02b56f2f57c31087185545454e53089e8176a23bd829c5177
4
- data.tar.gz: 392489743d1863336597fc19039c1fd0077c5735b096de799f8adf61a5c29dbe
3
+ metadata.gz: f5b29096324f4d5c2effbe82e606b7c4d15dcfc51d447f387389fd2a30a0a399
4
+ data.tar.gz: 7430f646c26f19d709da049de86dc3befe2226900d7eb246ae6aa74fa40be284
5
5
  SHA512:
6
- metadata.gz: 337fb13844251d627cecd341da3bc0a23b0addcc0b83f49f76e3fc0796852e24d71291712b270c79e3cb9e729bd2d831e4ca303a46dd4c7446404de6175b1f86
7
- data.tar.gz: 4d2b9734294ff4f154df4012bd8f21964e3627b29ade7c716079ad6a74c19713a0a0a287cb57315d642cac7fe9b521db21104e9ea89eef745babcf292b7a67d2
6
+ metadata.gz: c6eb24b2bdde0a88af4df1fd80eaa5553a4dfbba55351c8f9b4c9b4124e7c77d7ac1ea0579d5c2b4a30ecd23ebf0e9bdb436624888cd4e02f87e0a295391a9c3
7
+ data.tar.gz: 7c4f70bfdc422a0188c8f99aeaaf5002475457859bbe0a7d2bed95d06c61b47fa89deec2bb5f3e633858f3abe18d4ca374f22b2779a256a50e110370e067e0e1
data/LICENSE ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/bigdecimal.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.require_paths = %w[lib]
25
25
  s.files = %w[
26
+ LICENSE
26
27
  bigdecimal.gemspec
27
28
  lib/bigdecimal.rb
28
29
  lib/bigdecimal/jacobian.rb
@@ -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.6"
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;
@@ -7229,7 +7230,7 @@ VpSqrt(Real *y, Real *x)
7229
7230
  y->MaxPrec = Min((size_t)n , y_prec);
7230
7231
  f->MaxPrec = y->MaxPrec + 1;
7231
7232
  n = (SIGNED_VALUE)(y_prec * BASE_FIG);
7232
- if (n < (SIGNED_VALUE)maxnr) n = (SIGNED_VALUE)maxnr;
7233
+ if (n > (SIGNED_VALUE)maxnr) n = (SIGNED_VALUE)maxnr;
7233
7234
 
7234
7235
  /*
7235
7236
  * Perform: y_{n+1} = (y_n - x/y_n) / 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.6
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: 2024-01-18 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: This library provides arbitrary-precision decimal floating-point number
16
16
  class.
@@ -21,6 +21,7 @@ extensions:
21
21
  - ext/bigdecimal/extconf.rb
22
22
  extra_rdoc_files: []
23
23
  files:
24
+ - LICENSE
24
25
  - bigdecimal.gemspec
25
26
  - ext/bigdecimal/bigdecimal.c
26
27
  - ext/bigdecimal/bigdecimal.h
@@ -45,7 +46,7 @@ licenses:
45
46
  - Ruby
46
47
  - BSD-2-Clause
47
48
  metadata: {}
48
- post_install_message:
49
+ post_install_message:
49
50
  rdoc_options: []
50
51
  require_paths:
51
52
  - lib
@@ -60,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  requirements: []
63
- rubygems_version: 3.3.13
64
- signing_key:
64
+ rubygems_version: 3.6.0.dev
65
+ signing_key:
65
66
  specification_version: 4
66
67
  summary: Arbitrary-precision decimal floating-point number library.
67
68
  test_files: []