bigdecimal 3.1.0 → 3.1.6

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.
@@ -102,7 +102,7 @@ extern VALUE rb_cBigDecimal;
102
102
  */
103
103
  #define VP_EXPORT static
104
104
 
105
- /* Exception codes */
105
+ /* Exception mode */
106
106
  #define VP_EXCEPTION_ALL ((unsigned short)0x00FF)
107
107
  #define VP_EXCEPTION_INFINITY ((unsigned short)0x0001)
108
108
  #define VP_EXCEPTION_NaN ((unsigned short)0x0002)
@@ -115,18 +115,36 @@ extern VALUE rb_cBigDecimal;
115
115
 
116
116
  #define BIGDECIMAL_EXCEPTION_MODE_DEFAULT 0U
117
117
 
118
- /* Computation mode */
118
+ /* This is used in BigDecimal#mode */
119
119
  #define VP_ROUND_MODE ((unsigned short)0x0100)
120
- #define VP_ROUND_UP 1
121
- #define VP_ROUND_DOWN 2
122
- #define VP_ROUND_HALF_UP 3
123
- #define VP_ROUND_HALF_DOWN 4
124
- #define VP_ROUND_CEIL 5
125
- #define VP_ROUND_FLOOR 6
126
- #define VP_ROUND_HALF_EVEN 7
120
+
121
+ /* Rounding mode */
122
+ #define VP_ROUND_UP RBD_ROUND_UP
123
+ #define VP_ROUND_DOWN RBD_ROUND_DOWN
124
+ #define VP_ROUND_HALF_UP RBD_ROUND_HALF_UP
125
+ #define VP_ROUND_HALF_DOWN RBD_ROUND_HALF_DOWN
126
+ #define VP_ROUND_CEIL RBD_ROUND_CEIL
127
+ #define VP_ROUND_FLOOR RBD_ROUND_FLOOR
128
+ #define VP_ROUND_HALF_EVEN RBD_ROUND_HALF_EVEN
129
+
130
+ enum rbd_rounding_mode {
131
+ RBD_ROUND_UP = 1,
132
+ RBD_ROUND_DOWN = 2,
133
+ RBD_ROUND_HALF_UP = 3,
134
+ RBD_ROUND_HALF_DOWN = 4,
135
+ RBD_ROUND_CEIL = 5,
136
+ RBD_ROUND_FLOOR = 6,
137
+ RBD_ROUND_HALF_EVEN = 7,
138
+
139
+ RBD_ROUND_DEFAULT = RBD_ROUND_HALF_UP,
140
+ RBD_ROUND_TRUNCATE = RBD_ROUND_DOWN,
141
+ RBD_ROUND_BANKER = RBD_ROUND_HALF_EVEN,
142
+ RBD_ROUND_CEILING = RBD_ROUND_CEIL
143
+ };
127
144
 
128
145
  #define BIGDECIMAL_ROUNDING_MODE_DEFAULT VP_ROUND_HALF_UP
129
146
 
147
+ /* Sign flag */
130
148
  #define VP_SIGN_NaN 0 /* NaN */
131
149
  #define VP_SIGN_POSITIVE_ZERO 1 /* Positive zero */
132
150
  #define VP_SIGN_NEGATIVE_ZERO -1 /* Negative zero */
@@ -135,6 +153,7 @@ extern VALUE rb_cBigDecimal;
135
153
  #define VP_SIGN_POSITIVE_INFINITE 3 /* Positive infinite number */
136
154
  #define VP_SIGN_NEGATIVE_INFINITE -3 /* Negative infinite number */
137
155
 
156
+ /* The size of fraction part array */
138
157
  #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
139
158
  #define FLEXIBLE_ARRAY_SIZE /* */
140
159
  #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
@@ -205,9 +224,6 @@ VP_EXPORT int VpIsNegDoubleZero(double v);
205
224
  #endif
206
225
  VP_EXPORT size_t VpNumOfChars(Real *vp,const char *pszFmt);
207
226
  VP_EXPORT size_t VpInit(DECDIG BaseVal);
208
- VP_EXPORT void *VpMemAlloc(size_t mb);
209
- VP_EXPORT void *VpMemRealloc(void *ptr, size_t mb);
210
- VP_EXPORT void VpFree(Real *pv);
211
227
  VP_EXPORT Real *VpAlloc(size_t mx, const char *szVal, int strict_p, int exc);
212
228
  VP_EXPORT size_t VpAsgn(Real *c, Real *a, int isw);
213
229
  VP_EXPORT size_t VpAddSub(Real *c,Real *a,Real *b,int operation);
@@ -215,10 +231,10 @@ VP_EXPORT size_t VpMult(Real *c,Real *a,Real *b);
215
231
  VP_EXPORT size_t VpDivd(Real *c,Real *r,Real *a,Real *b);
216
232
  VP_EXPORT int VpComp(Real *a,Real *b);
217
233
  VP_EXPORT ssize_t VpExponent10(Real *a);
218
- VP_EXPORT void VpSzMantissa(Real *a,char *psz);
219
- VP_EXPORT int VpToSpecialString(Real *a,char *psz,int fPlus);
220
- VP_EXPORT void VpToString(Real *a, char *psz, size_t fFmt, int fPlus);
221
- VP_EXPORT void VpToFString(Real *a, char *psz, size_t fFmt, int fPlus);
234
+ VP_EXPORT void VpSzMantissa(Real *a, char *buf, size_t bufsize);
235
+ VP_EXPORT int VpToSpecialString(Real *a, char *buf, size_t bufsize, int fPlus);
236
+ VP_EXPORT void VpToString(Real *a, char *buf, size_t bufsize, size_t fFmt, int fPlus);
237
+ VP_EXPORT void VpToFString(Real *a, char *buf, size_t bufsize, size_t fFmt, int fPlus);
222
238
  VP_EXPORT int VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, const char *exp_chr, size_t ne);
223
239
  VP_EXPORT int VpVtoD(double *d, SIGNED_VALUE *e, Real *m);
224
240
  VP_EXPORT void VpDtoV(Real *m,double d);
@@ -1,18 +1,6 @@
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
- bigdecimal_version = File.read(gemspec_path).match(/^\s*s\.version\s+=\s+['"]([^'"]+)['"]\s*$/)[1]
7
-
8
- version_components = bigdecimal_version.split('.')
9
- bigdecimal_version = version_components[0, 3].join('.')
10
- bigdecimal_version << "-#{version_components[3]}" if version_components[3]
11
- $defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
12
-
13
- message "#{bigdecimal_version}\n"
14
- end
15
-
16
4
  def have_builtin_func(name, check_expr, opt = "", &b)
17
5
  checking_for checking_message(name.funcall_style, nil, opt) do
18
6
  if try_compile(<<SRC, opt, &b)
@@ -27,18 +15,6 @@ SRC
27
15
  end
28
16
  end
29
17
 
30
- gemspec_name = gemspec_path = nil
31
- unless ['', '../../'].any? {|dir|
32
- gemspec_name = "#{dir}bigdecimal.gemspec"
33
- gemspec_path = File.expand_path("../#{gemspec_name}", __FILE__)
34
- File.file?(gemspec_path)
35
- }
36
- $stderr.puts "Unable to find bigdecimal.gemspec"
37
- abort
38
- end
39
-
40
- check_bigdecimal_version(gemspec_path)
41
-
42
18
  have_builtin_func("__builtin_clz", "__builtin_clz(0)")
43
19
  have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
44
20
  have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
@@ -67,14 +43,10 @@ have_header("ruby/atomic.h")
67
43
  have_header("ruby/internal/has/builtin.h")
68
44
  have_header("ruby/internal/static_assert.h")
69
45
 
70
- have_type("struct RRational", "ruby.h")
71
46
  have_func("rb_rational_num", "ruby.h")
72
47
  have_func("rb_rational_den", "ruby.h")
73
- have_type("struct RComplex", "ruby.h")
74
48
  have_func("rb_complex_real", "ruby.h")
75
49
  have_func("rb_complex_imag", "ruby.h")
76
- have_func("rb_array_const_ptr", "ruby.h")
77
- have_func("rb_sym2str", "ruby.h")
78
50
  have_func("rb_opts_exception_p", "ruby.h")
79
51
  have_func("rb_category_warn", "ruby.h")
80
52
  have_const("RB_WARN_CATEGORY_DEPRECATED", "ruby.h")
@@ -86,6 +58,5 @@ else
86
58
  end
87
59
 
88
60
  create_makefile('bigdecimal') {|mf|
89
- mf << "GEMSPEC = #{gemspec_name}\n"
90
61
  mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n"
91
62
  }
@@ -35,10 +35,10 @@ extern "C" {
35
35
  #endif /* RB_UNUSED_VAR */
36
36
 
37
37
  #if defined(_MSC_VER) && _MSC_VER >= 1310
38
- # define HAVE___ASSUME
38
+ # define HAVE___ASSUME 1
39
39
 
40
40
  #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1300
41
- # define HAVE___ASSUME
41
+ # define HAVE___ASSUME 1
42
42
  #endif
43
43
 
44
44
  #ifndef UNREACHABLE
@@ -126,7 +126,7 @@ char *BigDecimal_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, c
126
126
  static inline VALUE
127
127
  rb_rational_num(VALUE rat)
128
128
  {
129
- #ifdef HAVE_TYPE_STRUCT_RRATIONAL
129
+ #ifdef RRATIONAL
130
130
  return RRATIONAL(rat)->num;
131
131
  #else
132
132
  return rb_funcall(rat, rb_intern("numerator"), 0);
@@ -138,7 +138,7 @@ rb_rational_num(VALUE rat)
138
138
  static inline VALUE
139
139
  rb_rational_den(VALUE rat)
140
140
  {
141
- #ifdef HAVE_TYPE_STRUCT_RRATIONAL
141
+ #ifdef RRATIONAL
142
142
  return RRATIONAL(rat)->den;
143
143
  #else
144
144
  return rb_funcall(rat, rb_intern("denominator"), 0);
@@ -152,7 +152,7 @@ rb_rational_den(VALUE rat)
152
152
  static inline VALUE
153
153
  rb_complex_real(VALUE cmp)
154
154
  {
155
- #ifdef HAVE_TYPE_STRUCT_RCOMPLEX
155
+ #ifdef RCOMPLEX
156
156
  return RCOMPLEX(cmp)->real;
157
157
  #else
158
158
  return rb_funcall(cmp, rb_intern("real"), 0);
@@ -164,7 +164,7 @@ rb_complex_real(VALUE cmp)
164
164
  static inline VALUE
165
165
  rb_complex_imag(VALUE cmp)
166
166
  {
167
- # ifdef HAVE_TYPE_STRUCT_RCOMPLEX
167
+ # ifdef RCOMPLEX
168
168
  return RCOMPLEX(cmp)->imag;
169
169
  # else
170
170
  return rb_funcall(cmp, rb_intern("imag"), 0);
@@ -172,45 +172,6 @@ rb_complex_imag(VALUE cmp)
172
172
  }
173
173
  #endif
174
174
 
175
- /* array */
176
-
177
- #ifndef FIX_CONST_VALUE_PTR
178
- # if defined(__fcc__) || defined(__fcc_version) || \
179
- defined(__FCC__) || defined(__FCC_VERSION)
180
- /* workaround for old version of Fujitsu C Compiler (fcc) */
181
- # define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x))
182
- # else
183
- # define FIX_CONST_VALUE_PTR(x) (x)
184
- # endif
185
- #endif
186
-
187
- #ifndef HAVE_RB_ARRAY_CONST_PTR
188
- static inline const VALUE *
189
- rb_array_const_ptr(VALUE a)
190
- {
191
- return FIX_CONST_VALUE_PTR((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ?
192
- RARRAY(a)->as.ary : RARRAY(a)->as.heap.ptr);
193
- }
194
- #endif
195
-
196
- #ifndef RARRAY_CONST_PTR
197
- # define RARRAY_CONST_PTR(a) rb_array_const_ptr(a)
198
- #endif
199
-
200
- #ifndef RARRAY_AREF
201
- # define RARRAY_AREF(a, i) (RARRAY_CONST_PTR(a)[i])
202
- #endif
203
-
204
- /* symbol */
205
-
206
- #ifndef HAVE_RB_SYM2STR
207
- static inline VALUE
208
- rb_sym2str(VALUE sym)
209
- {
210
- return rb_id2str(SYM2ID(sym));
211
- }
212
- #endif
213
-
214
175
  /* st */
215
176
 
216
177
  #ifndef ST2FIX
@@ -42,8 +42,8 @@ module Jacobian
42
42
  end
43
43
 
44
44
 
45
- # Computes the derivative of f[i] at x[i].
46
- # fx is the value of f at x.
45
+ # Computes the derivative of +f[i]+ at +x[i]+.
46
+ # +fx+ is the value of +f+ at +x+.
47
47
  def dfdxi(f,fx,x,i)
48
48
  nRetry = 0
49
49
  n = x.size
@@ -75,7 +75,7 @@ module Jacobian
75
75
  deriv
76
76
  end
77
77
 
78
- # Computes the Jacobian of f at x. fx is the value of f at x.
78
+ # Computes the Jacobian of +f+ at +x+. +fx+ is the value of +f+ at +x+.
79
79
  def jacobian(f,fx,x)
80
80
  n = x.size
81
81
  dfdx = Array.new(n*n)
@@ -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)
@@ -33,15 +33,19 @@ class Float < Numeric
33
33
  #
34
34
  # Returns the value of +float+ as a BigDecimal.
35
35
  # The +precision+ parameter is used to determine the number of
36
- # significant digits for the result (the default is Float::DIG).
36
+ # significant digits for the result. When +precision+ is set to +0+,
37
+ # the number of digits to represent the float being converted is determined
38
+ # automatically.
39
+ # The default +precision+ is +0+.
37
40
  #
38
41
  # require 'bigdecimal'
39
42
  # require 'bigdecimal/util'
40
43
  #
41
44
  # 0.5.to_d # => 0.5e0
45
+ # 1.234.to_d # => 0.1234e1
42
46
  # 1.234.to_d(2) # => 0.12e1
43
47
  #
44
- # See also BigDecimal::new.
48
+ # See also Kernel.BigDecimal.
45
49
  #
46
50
  def to_d(precision=0)
47
51
  BigDecimal(self, precision)
@@ -63,7 +67,7 @@ class String
63
67
  # "123.45e1".to_d # => 0.12345e4
64
68
  # "45.67 degrees".to_d # => 0.4567e2
65
69
  #
66
- # See also BigDecimal::new.
70
+ # See also Kernel.BigDecimal.
67
71
  #
68
72
  def to_d
69
73
  BigDecimal.interpret_loosely(self)
@@ -123,7 +127,7 @@ class Rational < Numeric
123
127
  #
124
128
  # Rational(22, 7).to_d(3) # => 0.314e1
125
129
  #
126
- # See also BigDecimal::new.
130
+ # See also Kernel.BigDecimal.
127
131
  #
128
132
  def to_d(precision)
129
133
  BigDecimal(self, precision)
@@ -148,7 +152,7 @@ class Complex < Numeric
148
152
  # Complex(0.1234567, 0).to_d(4) # => 0.1235e0
149
153
  # Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
150
154
  #
151
- # See also BigDecimal::new.
155
+ # See also Kernel.BigDecimal.
152
156
  #
153
157
  def to_d(*args)
154
158
  BigDecimal(self) unless self.imag.zero? # to raise eerror
data/lib/bigdecimal.rb CHANGED
@@ -1 +1,5 @@
1
- require 'bigdecimal.so'
1
+ if RUBY_ENGINE == 'jruby'
2
+ JRuby::Util.load_ext("org.jruby.ext.bigdecimal.BigDecimalLibrary")
3
+ else
4
+ require 'bigdecimal.so'
5
+ end
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.0
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: 2021-12-21 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
@@ -43,8 +44,9 @@ files:
43
44
  homepage: https://github.com/ruby/bigdecimal
44
45
  licenses:
45
46
  - Ruby
47
+ - BSD-2-Clause
46
48
  metadata: {}
47
- post_install_message:
49
+ post_install_message:
48
50
  rdoc_options: []
49
51
  require_paths:
50
52
  - lib
@@ -59,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
61
  - !ruby/object:Gem::Version
60
62
  version: '0'
61
63
  requirements: []
62
- rubygems_version: 3.2.23
63
- signing_key:
64
+ rubygems_version: 3.6.0.dev
65
+ signing_key:
64
66
  specification_version: 4
65
67
  summary: Arbitrary-precision decimal floating-point number library.
66
68
  test_files: []