bigdecimal 3.1.2 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bigdecimal.gemspec +28 -12
- data/ext/bigdecimal/bigdecimal.c +825 -586
- data/ext/bigdecimal/bigdecimal.h +32 -16
- data/ext/bigdecimal/extconf.rb +0 -29
- data/ext/bigdecimal/missing.h +6 -45
- data/lib/bigdecimal/jacobian.rb +3 -3
- data/lib/bigdecimal/util.rb +5 -1
- data/lib/bigdecimal.rb +5 -1
- metadata +4 -3
data/ext/bigdecimal/bigdecimal.h
CHANGED
@@ -102,7 +102,7 @@ extern VALUE rb_cBigDecimal;
|
|
102
102
|
*/
|
103
103
|
#define VP_EXPORT static
|
104
104
|
|
105
|
-
/* Exception
|
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
|
-
/*
|
118
|
+
/* This is used in BigDecimal#mode */
|
119
119
|
#define VP_ROUND_MODE ((unsigned short)0x0100)
|
120
|
-
|
121
|
-
|
122
|
-
#define
|
123
|
-
#define
|
124
|
-
#define
|
125
|
-
#define
|
126
|
-
#define
|
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 *
|
219
|
-
VP_EXPORT int VpToSpecialString(Real *a,char *
|
220
|
-
VP_EXPORT void VpToString(Real *a, char *
|
221
|
-
VP_EXPORT void VpToFString(Real *a, char *
|
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);
|
data/ext/bigdecimal/extconf.rb
CHANGED
@@ -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
|
}
|
data/ext/bigdecimal/missing.h
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
data/lib/bigdecimal/jacobian.rb
CHANGED
@@ -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
|
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)
|
data/lib/bigdecimal/util.rb
CHANGED
@@ -33,12 +33,16 @@ 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
|
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
48
|
# See also BigDecimal::new.
|
data/lib/bigdecimal.rb
CHANGED
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: 3.1.
|
4
|
+
version: 3.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: This library provides arbitrary-precision decimal floating-point number
|
16
16
|
class.
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
homepage: https://github.com/ruby/bigdecimal
|
44
44
|
licenses:
|
45
45
|
- Ruby
|
46
|
+
- BSD-2-Clause
|
46
47
|
metadata: {}
|
47
48
|
post_install_message:
|
48
49
|
rdoc_options: []
|
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
62
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
63
|
+
rubygems_version: 3.3.13
|
63
64
|
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Arbitrary-precision decimal floating-point number library.
|