bigdecimal 1.4.2 → 2.0.2

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: 5ef8a298cdf9271292d1e8a98edb10b179fe4250c0e6c10eaaae68afe0a95659
4
- data.tar.gz: 0a75b502a86f3b31cf2a01a2bc49b2195c78e202a65ff8af1d515fff4a44b914
3
+ metadata.gz: f755d262f35a249de6848a00e3bf3b8d7a4816dc9a61bb81c099a22baa40bf66
4
+ data.tar.gz: f3b06716476c5da9c8a8006b6aeca492ac0206bce305c23910280fe0a0b28de1
5
5
  SHA512:
6
- metadata.gz: 1a942a904c859a53582239390da0a51bcee719c21efb4c567023f27faa73d7b4c737e8b0246f3dbaa2ffc3ffa4546a3bdd04ac7cfbbc7e940115afd2ad0df46d
7
- data.tar.gz: d632e8b92d656417ba71c35e7892607615c18bde828b0f685db506795bbd4811dd5c1211b08d9c240a2f2ab8f04b808f7514bd462243b7c7b668a9723ca379fd
6
+ metadata.gz: 35be1b5d13ee12b4b40ab3cf7277fb235fffcaf554f71107fe3b0727bcef9edb6b03c02bd7db0039505a575752a8014f41402775e8080ec9da2dcda184787df5
7
+ data.tar.gz: f4f063cc6cd0291cbac0f77b2fac485a1e064b08a8789e2ac7b796e6e36529a40a781783bc0417893e01985ad5fa37487c233e5da8fb88eb64c73774de2a9173
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- bigdecimal_version = '1.4.2'
3
+ bigdecimal_version = '2.0.2'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "bigdecimal"
@@ -11,19 +11,14 @@ 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
- s.extensions = %w[ext/bigdecimal/extconf.rb ext/bigdecimal/util/extconf.rb]
17
+ s.extensions = %w[ext/bigdecimal/extconf.rb]
18
18
  s.files = %w[
19
19
  bigdecimal.gemspec
20
20
  ext/bigdecimal/bigdecimal.c
21
- ext/bigdecimal/bigdecimal.def
22
21
  ext/bigdecimal/bigdecimal.h
23
- ext/bigdecimal/depend
24
- ext/bigdecimal/extconf.rb
25
- ext/bigdecimal/util/extconf.rb
26
- ext/bigdecimal/util/util.c
27
22
  lib/bigdecimal.rb
28
23
  lib/bigdecimal/jacobian.rb
29
24
  lib/bigdecimal/ludcmp.rb
@@ -35,11 +30,10 @@ Gem::Specification.new do |s|
35
30
  sample/pi.rb
36
31
  ]
37
32
 
38
- s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze)
33
+ s.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
39
34
 
40
- s.add_development_dependency "rake", "~> 10.0"
35
+ s.add_development_dependency "rake", ">= 12.3.3"
41
36
  s.add_development_dependency "rake-compiler", ">= 0.9"
42
- s.add_development_dependency "rake-compiler-dock", ">= 0.6.1"
43
37
  s.add_development_dependency "minitest", "< 5.0.0"
44
38
  s.add_development_dependency "pry"
45
39
  end
@@ -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>
@@ -127,6 +127,30 @@ rb_rational_den(VALUE rat)
127
127
  }
128
128
  #endif
129
129
 
130
+ #ifndef HAVE_RB_COMPLEX_REAL
131
+ static inline VALUE
132
+ rb_complex_real(VALUE cmp)
133
+ {
134
+ #ifdef HAVE_TYPE_STRUCT_RCOMPLEX
135
+ return RCOMPLEX(cmp)->real;
136
+ #else
137
+ return rb_funcall(cmp, rb_intern("real"), 0);
138
+ #endif
139
+ }
140
+ #endif
141
+
142
+ #ifndef HAVE_RB_COMPLEX_IMAG
143
+ static inline VALUE
144
+ rb_complex_imag(VALUE cmp)
145
+ {
146
+ #ifdef HAVE_TYPE_STRUCT_RCOMPLEX
147
+ return RCOMPLEX(cmp)->imag;
148
+ #else
149
+ return rb_funcall(cmp, rb_intern("imag"), 0);
150
+ #endif
151
+ }
152
+ #endif
153
+
130
154
  #define BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0)
131
155
  #define BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0)
132
156
 
@@ -276,7 +300,6 @@ again:
276
300
  #ifdef ENABLE_NUMERIC_STRING
277
301
  case T_STRING:
278
302
  StringValueCStr(v);
279
- rb_check_safe_obj(v);
280
303
  return VpCreateRbObject(RSTRING_LEN(v) + VpBaseFig() + 1,
281
304
  RSTRING_PTR(v));
282
305
  #endif /* ENABLE_NUMERIC_STRING */
@@ -344,8 +367,8 @@ BigDecimal_prec(VALUE self)
344
367
  VALUE obj;
345
368
 
346
369
  GUARD_OBJ(p, GetVpValue(self, 1));
347
- obj = rb_assoc_new(INT2NUM(p->Prec*VpBaseFig()),
348
- INT2NUM(p->MaxPrec*VpBaseFig()));
370
+ obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()),
371
+ SIZET2NUM(p->MaxPrec*VpBaseFig()));
349
372
  return obj;
350
373
  }
351
374
 
@@ -418,7 +441,6 @@ BigDecimal_load(VALUE self, VALUE str)
418
441
  unsigned long m=0;
419
442
 
420
443
  pch = (unsigned char *)StringValueCStr(str);
421
- rb_check_safe_obj(str);
422
444
  /* First get max prec */
423
445
  while((*pch) != (unsigned char)'\0' && (ch = *pch++) != (unsigned char)':') {
424
446
  if(!ISDIGIT(ch)) {
@@ -1756,20 +1778,23 @@ BigDecimal_fix(VALUE self)
1756
1778
  * round(n, mode)
1757
1779
  *
1758
1780
  * Round to the nearest integer (by default), returning the result as a
1759
- * BigDecimal.
1781
+ * BigDecimal if n is specified, or as an Integer if it isn't.
1760
1782
  *
1761
1783
  * BigDecimal('3.14159').round #=> 3
1762
1784
  * BigDecimal('8.7').round #=> 9
1763
1785
  * BigDecimal('-9.9').round #=> -10
1764
1786
  *
1787
+ * BigDecimal('3.14159').round(2).class.name #=> "BigDecimal"
1788
+ * BigDecimal('3.14159').round.class.name #=> "Integer"
1789
+ *
1765
1790
  * If n is specified and positive, the fractional part of the result has no
1766
1791
  * more than that many digits.
1767
1792
  *
1768
1793
  * If n is specified and negative, at least that many digits to the left of the
1769
- * decimal point will be 0 in the result.
1794
+ * decimal point will be 0 in the result, and return value will be an Integer.
1770
1795
  *
1771
1796
  * BigDecimal('3.14159').round(3) #=> 3.142
1772
- * BigDecimal('13345.234').round(-2) #=> 13300.0
1797
+ * BigDecimal('13345.234').round(-2) #=> 13300
1773
1798
  *
1774
1799
  * The value of the optional mode argument can be used to determine how
1775
1800
  * rounding is performed; see BigDecimal.mode.
@@ -1782,6 +1807,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1782
1807
  int iLoc = 0;
1783
1808
  VALUE vLoc;
1784
1809
  VALUE vRound;
1810
+ int round_to_int = 0;
1785
1811
  size_t mx, pl;
1786
1812
 
1787
1813
  unsigned short sw = VpGetRoundMode();
@@ -1789,6 +1815,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1789
1815
  switch (rb_scan_args(argc, argv, "02", &vLoc, &vRound)) {
1790
1816
  case 0:
1791
1817
  iLoc = 0;
1818
+ round_to_int = 1;
1792
1819
  break;
1793
1820
  case 1:
1794
1821
  if (RB_TYPE_P(vLoc, T_HASH)) {
@@ -1796,6 +1823,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1796
1823
  }
1797
1824
  else {
1798
1825
  iLoc = NUM2INT(vLoc);
1826
+ if (iLoc < 1) round_to_int = 1;
1799
1827
  }
1800
1828
  break;
1801
1829
  case 2:
@@ -1817,7 +1845,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
1817
1845
  GUARD_OBJ(c, VpCreateRbObject(mx, "0"));
1818
1846
  VpSetPrecLimit(pl);
1819
1847
  VpActiveRound(c, a, sw, iLoc);
1820
- if (argc == 0) {
1848
+ if (round_to_int) {
1821
1849
  return BigDecimal_to_i(ToValue(c));
1822
1850
  }
1823
1851
  return ToValue(c);
@@ -2027,7 +2055,6 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
2027
2055
  if (rb_scan_args(argc, argv, "01", &f) == 1) {
2028
2056
  if (RB_TYPE_P(f, T_STRING)) {
2029
2057
  psz = StringValueCStr(f);
2030
- rb_check_safe_obj(f);
2031
2058
  if (*psz == ' ') {
2032
2059
  fPlus = 1;
2033
2060
  psz++;
@@ -2067,7 +2094,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
2067
2094
  nc += (nc + mc - 1) / mc + 1;
2068
2095
  }
2069
2096
 
2070
- str = rb_str_new(0, nc);
2097
+ str = rb_usascii_str_new(0, nc);
2071
2098
  psz = RSTRING_PTR(str);
2072
2099
 
2073
2100
  if (fmt) {
@@ -2132,7 +2159,7 @@ BigDecimal_split(VALUE self)
2132
2159
  rb_ary_push(obj, str);
2133
2160
  rb_str_resize(str, strlen(psz1));
2134
2161
  rb_ary_push(obj, INT2FIX(10));
2135
- rb_ary_push(obj, INT2NUM(e));
2162
+ rb_ary_push(obj, SSIZET2NUM(e));
2136
2163
  return obj;
2137
2164
  }
2138
2165
 
@@ -2145,7 +2172,7 @@ static VALUE
2145
2172
  BigDecimal_exponent(VALUE self)
2146
2173
  {
2147
2174
  ssize_t e = VpExponent10(GetVpValue(self, 1));
2148
- return INT2NUM(e);
2175
+ return SSIZET2NUM(e);
2149
2176
  }
2150
2177
 
2151
2178
  /* Returns a string representation of self.
@@ -2338,7 +2365,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
2338
2365
  }
2339
2366
  goto retry;
2340
2367
  }
2341
- exp = GetVpValueWithPrec(vexp, DBL_DIG+1, 1);
2368
+ if (NIL_P(prec)) {
2369
+ n += DBLE_FIG;
2370
+ }
2371
+ exp = GetVpValueWithPrec(vexp, DBLE_FIG, 1);
2342
2372
  break;
2343
2373
 
2344
2374
  case T_RATIONAL:
@@ -2353,6 +2383,9 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
2353
2383
  goto retry;
2354
2384
  }
2355
2385
  exp = GetVpValueWithPrec(vexp, n, 1);
2386
+ if (NIL_P(prec)) {
2387
+ n += n;
2388
+ }
2356
2389
  break;
2357
2390
 
2358
2391
  case T_DATA:
@@ -2363,6 +2396,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
2363
2396
  vexp = BigDecimal_to_i(vexp);
2364
2397
  goto retry;
2365
2398
  }
2399
+ if (NIL_P(prec)) {
2400
+ GUARD_OBJ(y, GetVpValue(vexp, 1));
2401
+ n += y->Prec*VpBaseFig();
2402
+ }
2366
2403
  exp = DATA_PTR(vexp);
2367
2404
  break;
2368
2405
  }
@@ -2560,6 +2597,10 @@ BigDecimal_clone(VALUE self)
2560
2597
  return self;
2561
2598
  }
2562
2599
 
2600
+ #ifdef HAVE_RB_OPTS_EXCEPTION_P
2601
+ int rb_opts_exception_p(VALUE opts, int default_value);
2602
+ #define opts_exception_p(opts) rb_opts_exception_p((opts), 1)
2603
+ #else
2563
2604
  static int
2564
2605
  opts_exception_p(VALUE opts)
2565
2606
  {
@@ -2568,12 +2609,20 @@ opts_exception_p(VALUE opts)
2568
2609
  if (!kwds[0]) {
2569
2610
  kwds[0] = rb_intern_const("exception");
2570
2611
  }
2571
- rb_get_kwargs(opts, kwds, 0, 1, &exception);
2612
+ if (!rb_get_kwargs(opts, kwds, 0, 1, &exception)) return 1;
2613
+ switch (exception) {
2614
+ case Qtrue: case Qfalse:
2615
+ break;
2616
+ default:
2617
+ rb_raise(rb_eArgError, "true or false is expected as exception: %+"PRIsVALUE,
2618
+ exception);
2619
+ }
2572
2620
  return exception != Qfalse;
2573
2621
  }
2622
+ #endif
2574
2623
 
2575
2624
  static Real *
2576
- BigDecimal_new(int argc, VALUE *argv)
2625
+ VpNewVarArg(int argc, VALUE *argv)
2577
2626
  {
2578
2627
  size_t mf;
2579
2628
  VALUE opts = Qnil;
@@ -2616,6 +2665,7 @@ BigDecimal_new(int argc, VALUE *argv)
2616
2665
  }
2617
2666
  }
2618
2667
 
2668
+ retry:
2619
2669
  switch (TYPE(iniValue)) {
2620
2670
  case T_DATA:
2621
2671
  if (is_kind_of_BigDecimal(iniValue)) {
@@ -2653,6 +2703,18 @@ BigDecimal_new(int argc, VALUE *argv)
2653
2703
  }
2654
2704
  return GetVpValueWithPrec(iniValue, mf, 1);
2655
2705
 
2706
+ case T_COMPLEX:
2707
+ {
2708
+ VALUE im;
2709
+ im = rb_complex_imag(iniValue);
2710
+ if (!is_zero(im)) {
2711
+ rb_raise(rb_eArgError,
2712
+ "Unable to make a BigDecimal from non-zero imaginary number");
2713
+ }
2714
+ iniValue = rb_complex_real(iniValue);
2715
+ goto retry;
2716
+ }
2717
+
2656
2718
  case T_STRING:
2657
2719
  /* fall through */
2658
2720
  default:
@@ -2710,8 +2772,11 @@ f_BigDecimal(int argc, VALUE *argv, VALUE self)
2710
2772
  Real *pv;
2711
2773
  VALUE obj;
2712
2774
 
2775
+ if (argc > 0 && CLASS_OF(argv[0]) == rb_cBigDecimal) {
2776
+ if (argc == 1 || (argc == 2 && RB_TYPE_P(argv[1], T_HASH))) return argv[0];
2777
+ }
2713
2778
  obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0);
2714
- pv = BigDecimal_new(argc, argv);
2779
+ pv = VpNewVarArg(argc, argv);
2715
2780
  if (pv == NULL) return Qnil;
2716
2781
  SAVE(pv);
2717
2782
  if (ToValue(pv)) pv = VpCopy(NULL, pv);
@@ -2720,6 +2785,20 @@ f_BigDecimal(int argc, VALUE *argv, VALUE self)
2720
2785
  return pv->obj = obj;
2721
2786
  }
2722
2787
 
2788
+ static VALUE
2789
+ BigDecimal_s_interpret_loosely(VALUE klass, VALUE str)
2790
+ {
2791
+ ENTER(1);
2792
+ char const *c_str;
2793
+ Real *pv;
2794
+
2795
+ c_str = StringValueCStr(str);
2796
+ GUARD_OBJ(pv, VpAlloc(0, c_str, 0, 1));
2797
+ pv->obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, pv);
2798
+ RB_OBJ_FREEZE(pv->obj);
2799
+ return pv->obj;
2800
+ }
2801
+
2723
2802
  /* call-seq:
2724
2803
  * BigDecimal.limit(digits)
2725
2804
  *
@@ -2736,7 +2815,7 @@ static VALUE
2736
2815
  BigDecimal_limit(int argc, VALUE *argv, VALUE self)
2737
2816
  {
2738
2817
  VALUE nFig;
2739
- VALUE nCur = INT2NUM(VpGetPrecLimit());
2818
+ VALUE nCur = SIZET2NUM(VpGetPrecLimit());
2740
2819
 
2741
2820
  if (rb_scan_args(argc, argv, "01", &nFig) == 1) {
2742
2821
  int nf;
@@ -2939,6 +3018,10 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
2939
3018
  n = prec + rmpd_double_figures();
2940
3019
  negative = BIGDECIMAL_NEGATIVE_P(vx);
2941
3020
  if (negative) {
3021
+ VALUE x_zero = INT2NUM(1);
3022
+ VALUE x_copy = f_BigDecimal(1, &x_zero, klass);
3023
+ x = BigDecimal_initialize_copy(x_copy, x);
3024
+ vx = DATA_PTR(x);
2942
3025
  VpSetSign(vx, 1);
2943
3026
  }
2944
3027
 
@@ -3140,20 +3223,6 @@ get_vp_value:
3140
3223
  return y;
3141
3224
  }
3142
3225
 
3143
- VALUE
3144
- rmpd_util_str_to_d(VALUE str)
3145
- {
3146
- ENTER(1);
3147
- char const *c_str;
3148
- Real *pv;
3149
-
3150
- c_str = StringValueCStr(str);
3151
- GUARD_OBJ(pv, VpAlloc(0, c_str, 0, 1));
3152
- pv->obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, pv);
3153
- RB_OBJ_FREEZE(pv->obj);
3154
- return pv->obj;
3155
- }
3156
-
3157
3226
  /* Document-class: BigDecimal
3158
3227
  * BigDecimal provides arbitrary-precision floating point decimal arithmetic.
3159
3228
  *
@@ -3300,6 +3369,7 @@ Init_bigdecimal(void)
3300
3369
  /* Class methods */
3301
3370
  rb_undef_method(CLASS_OF(rb_cBigDecimal), "allocate");
3302
3371
  rb_undef_method(CLASS_OF(rb_cBigDecimal), "new");
3372
+ rb_define_singleton_method(rb_cBigDecimal, "interpret_loosely", BigDecimal_s_interpret_loosely, 1);
3303
3373
  rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
3304
3374
  rb_define_singleton_method(rb_cBigDecimal, "limit", BigDecimal_limit, -1);
3305
3375
  rb_define_singleton_method(rb_cBigDecimal, "double_fig", BigDecimal_double_fig, 0);
@@ -3430,7 +3500,6 @@ Init_bigdecimal(void)
3430
3500
 
3431
3501
 
3432
3502
  /* instance methods */
3433
- rb_define_method(rb_cBigDecimal, "initialize_copy", BigDecimal_initialize_copy, 1);
3434
3503
  rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0);
3435
3504
 
3436
3505
  rb_define_method(rb_cBigDecimal, "add", BigDecimal_add2, 2);
@@ -4124,7 +4193,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
4124
4193
  /* at least mx digits. */
4125
4194
  /* szVal==NULL ==> allocate zero value. */
4126
4195
  vp = VpAllocReal(mx);
4127
- /* xmalloc() alway returns(or throw interruption) */
4196
+ /* xmalloc() always returns(or throw interruption) */
4128
4197
  vp->MaxPrec = mx; /* set max precision */
4129
4198
  VpSetZero(vp, 1); /* initialize vp to zero. */
4130
4199
  return vp;
@@ -4281,7 +4350,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
4281
4350
 
4282
4351
  psz[i] = '\0';
4283
4352
 
4284
- if (((ni == 0 || dot_seen) && nf == 0) || (exp_seen && ne == 0)) {
4353
+ if (strict_p && (((ni == 0 || dot_seen) && nf == 0) || (exp_seen && ne == 0))) {
4285
4354
  VALUE str;
4286
4355
  invalid_value:
4287
4356
  if (!strict_p) {
@@ -4300,7 +4369,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
4300
4369
  nalloc = Max(nalloc, mx);
4301
4370
  mx = nalloc;
4302
4371
  vp = VpAllocReal(mx);
4303
- /* xmalloc() alway returns(or throw interruption) */
4372
+ /* xmalloc() always returns(or throw interruption) */
4304
4373
  vp->MaxPrec = mx; /* set max precision */
4305
4374
  VpSetZero(vp, sign);
4306
4375
  VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne);
@@ -1,6 +1,21 @@
1
1
  # frozen_string_literal: false
2
2
  require 'mkmf'
3
3
 
4
+ def check_bigdecimal_version(gemspec_path)
5
+ message "checking RUBY_BIGDECIMAL_VERSION... "
6
+
7
+ bigdecimal_version =
8
+ IO.readlines(gemspec_path)
9
+ .grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([^\']+)\'/, 1]
10
+
11
+ version_components = bigdecimal_version.split('.')
12
+ bigdecimal_version = version_components[0, 3].join('.')
13
+ bigdecimal_version << "-#{version_components[3]}" if version_components[3]
14
+ $defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
15
+
16
+ message "#{bigdecimal_version}\n"
17
+ end
18
+
4
19
  gemspec_name = gemspec_path = nil
5
20
  unless ['', '../../'].any? {|dir|
6
21
  gemspec_name = "#{dir}bigdecimal.gemspec"
@@ -11,11 +26,7 @@ unless ['', '../../'].any? {|dir|
11
26
  abort
12
27
  end
13
28
 
14
- bigdecimal_version =
15
- IO.readlines(gemspec_path)
16
- .grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([\d\.]+)\'/, 1]
17
-
18
- $defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
29
+ check_bigdecimal_version(gemspec_path)
19
30
 
20
31
  have_func("labs", "stdlib.h")
21
32
  have_func("llabs", "stdlib.h")
@@ -25,8 +36,12 @@ have_func("isfinite", "math.h")
25
36
  have_type("struct RRational", "ruby.h")
26
37
  have_func("rb_rational_num", "ruby.h")
27
38
  have_func("rb_rational_den", "ruby.h")
39
+ have_type("struct RComplex", "ruby.h")
40
+ have_func("rb_complex_real", "ruby.h")
41
+ have_func("rb_complex_imag", "ruby.h")
28
42
  have_func("rb_array_const_ptr", "ruby.h")
29
43
  have_func("rb_sym2str", "ruby.h")
44
+ have_func("rb_opts_exception_p", "ruby.h")
30
45
 
31
46
  if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__))
32
47
  bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb"
@@ -1,10 +1 @@
1
- begin
2
- require "#{RUBY_VERSION[/\d+\.\d+/]}/bigdecimal.so"
3
- rescue LoadError
4
- require 'bigdecimal.so'
5
- end
6
-
7
- def BigDecimal.new(*args, **kwargs)
8
- warn "BigDecimal.new is deprecated; use BigDecimal() method instead.", uplevel: 1
9
- BigDecimal(*args, **kwargs)
10
- end
1
+ require 'bigdecimal.so'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: false
2
- #
2
+
3
+ require 'bigdecimal'
4
+
3
5
  # require 'bigdecimal/jacobian'
4
6
  #
5
7
  # Provides methods to compute the Jacobian matrix of a set of equations at a
@@ -21,9 +23,6 @@
21
23
  #
22
24
  # fx is f.values(x).
23
25
  #
24
-
25
- require 'bigdecimal'
26
-
27
26
  module Jacobian
28
27
  module_function
29
28
 
@@ -6,7 +6,6 @@
6
6
  #++
7
7
 
8
8
  require 'bigdecimal'
9
- require 'bigdecimal/util.so'
10
9
 
11
10
  class Integer < Numeric
12
11
  # call-seq:
@@ -66,6 +65,9 @@ class String
66
65
  #
67
66
  # See also BigDecimal::new.
68
67
  #
68
+ def to_d
69
+ BigDecimal.interpret_loosely(self)
70
+ end
69
71
  end
70
72
 
71
73
 
@@ -129,6 +131,39 @@ class Rational < Numeric
129
131
  end
130
132
 
131
133
 
134
+ class Complex < Numeric
135
+ # call-seq:
136
+ # cmp.to_d -> bigdecimal
137
+ # cmp.to_d(precision) -> bigdecimal
138
+ #
139
+ # Returns the value as a BigDecimal.
140
+ #
141
+ # The +precision+ parameter is required for a rational complex number.
142
+ # This parameter is used to determine the number of significant digits
143
+ # for the result.
144
+ #
145
+ # require 'bigdecimal'
146
+ # require 'bigdecimal/util'
147
+ #
148
+ # Complex(0.1234567, 0).to_d(4) # => 0.1235e0
149
+ # Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
150
+ #
151
+ # See also BigDecimal::new.
152
+ #
153
+ def to_d(*args)
154
+ BigDecimal(self) unless self.imag.zero? # to raise eerror
155
+
156
+ if args.length == 0
157
+ case self.real
158
+ when Rational
159
+ BigDecimal(self.real) # to raise error
160
+ end
161
+ end
162
+ self.real.to_d(*args)
163
+ end
164
+ end
165
+
166
+
132
167
  class NilClass
133
168
  # call-seq:
134
169
  # nil.to_d -> bigdecimal
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: 1.4.2
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: 2018-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
@@ -40,20 +40,6 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0.9'
43
- - !ruby/object:Gem::Dependency
44
- name: rake-compiler-dock
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.6.1
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.6.1
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: minitest
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -89,17 +75,12 @@ email:
89
75
  executables: []
90
76
  extensions:
91
77
  - ext/bigdecimal/extconf.rb
92
- - ext/bigdecimal/util/extconf.rb
93
78
  extra_rdoc_files: []
94
79
  files:
95
80
  - bigdecimal.gemspec
96
81
  - ext/bigdecimal/bigdecimal.c
97
- - ext/bigdecimal/bigdecimal.def
98
82
  - ext/bigdecimal/bigdecimal.h
99
- - ext/bigdecimal/depend
100
83
  - ext/bigdecimal/extconf.rb
101
- - ext/bigdecimal/util/extconf.rb
102
- - ext/bigdecimal/util/util.c
103
84
  - lib/bigdecimal.rb
104
85
  - lib/bigdecimal/jacobian.rb
105
86
  - lib/bigdecimal/ludcmp.rb
@@ -111,7 +92,7 @@ files:
111
92
  - sample/pi.rb
112
93
  homepage: https://github.com/ruby/bigdecimal
113
94
  licenses:
114
- - ruby
95
+ - Ruby
115
96
  metadata: {}
116
97
  post_install_message:
117
98
  rdoc_options: []
@@ -121,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
102
  requirements:
122
103
  - - ">="
123
104
  - !ruby/object:Gem::Version
124
- version: 2.3.0
105
+ version: 2.4.0
125
106
  required_rubygems_version: !ruby/object:Gem::Requirement
126
107
  requirements:
127
108
  - - ">="
128
109
  - !ruby/object:Gem::Version
129
110
  version: '0'
130
111
  requirements: []
131
- rubygems_version: 3.0.1
112
+ rubygems_version: 3.1.4
132
113
  signing_key:
133
114
  specification_version: 4
134
115
  summary: Arbitrary-precision decimal floating-point number library.
@@ -1,3 +0,0 @@
1
- EXPORTS
2
- rmpd_util_str_to_d
3
- Init_bigdecimal
@@ -1,16 +0,0 @@
1
- extconf.h: $(srcdir)/$(GEMSPEC)
2
- Makefile: $(BIGDECIMAL_RB)
3
-
4
- # AUTOGENERATED DEPENDENCIES START
5
- bigdecimal.o: $(RUBY_EXTCONF_H)
6
- bigdecimal.o: $(arch_hdrdir)/ruby/config.h
7
- bigdecimal.o: $(hdrdir)/ruby/defines.h
8
- bigdecimal.o: $(hdrdir)/ruby/intern.h
9
- bigdecimal.o: $(hdrdir)/ruby/missing.h
10
- bigdecimal.o: $(hdrdir)/ruby/ruby.h
11
- bigdecimal.o: $(hdrdir)/ruby/st.h
12
- bigdecimal.o: $(hdrdir)/ruby/subst.h
13
- bigdecimal.o: $(hdrdir)/ruby/util.h
14
- bigdecimal.o: bigdecimal.c
15
- bigdecimal.o: bigdecimal.h
16
- # AUTOGENERATED DEPENDENCIES END
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'mkmf'
3
-
4
- checking_for(checking_message("Windows")) do
5
- case RUBY_PLATFORM
6
- when /cygwin|mingw/
7
- if ARGV.include?('-rdevkit') # check `rake -rdevkit compile` case
8
- base_dir = File.expand_path('../../../..', __FILE__)
9
- build_dir = File.join(base_dir, "tmp", RUBY_PLATFORM, "bigdecimal", RUBY_VERSION, "")
10
- else
11
- build_dir = "$(TARGET_SO_DIR)../"
12
- end
13
- $libs << " #{build_dir}bigdecimal.so"
14
- true
15
- when /mswin/
16
- $DLDFLAGS << " -libpath:.."
17
- $libs << " bigdecimal-$(arch).lib"
18
- true
19
- else
20
- false
21
- end
22
- end
23
-
24
- create_makefile('bigdecimal/util')
@@ -1,9 +0,0 @@
1
- #include "ruby.h"
2
-
3
- RUBY_EXTERN VALUE rmpd_util_str_to_d(VALUE str);
4
-
5
- void
6
- Init_util(void)
7
- {
8
- rb_define_method(rb_cString, "to_d", rmpd_util_str_to_d, 0);
9
- }