bigdecimal 3.1.1 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bigdecimal.gemspec +2 -2
- data/ext/bigdecimal/bigdecimal.c +809 -584
- data/ext/bigdecimal/bigdecimal.h +32 -16
- data/ext/bigdecimal/extconf.rb +0 -4
- data/ext/bigdecimal/missing.h +6 -45
- data/lib/bigdecimal/jacobian.rb +3 -3
- data/lib/bigdecimal/util.rb +5 -1
- metadata +7 -6
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
@@ -67,14 +67,10 @@ have_header("ruby/atomic.h")
|
|
67
67
|
have_header("ruby/internal/has/builtin.h")
|
68
68
|
have_header("ruby/internal/static_assert.h")
|
69
69
|
|
70
|
-
have_type("struct RRational", "ruby.h")
|
71
70
|
have_func("rb_rational_num", "ruby.h")
|
72
71
|
have_func("rb_rational_den", "ruby.h")
|
73
|
-
have_type("struct RComplex", "ruby.h")
|
74
72
|
have_func("rb_complex_real", "ruby.h")
|
75
73
|
have_func("rb_complex_imag", "ruby.h")
|
76
|
-
have_func("rb_array_const_ptr", "ruby.h")
|
77
|
-
have_func("rb_sym2str", "ruby.h")
|
78
74
|
have_func("rb_opts_exception_p", "ruby.h")
|
79
75
|
have_func("rb_category_warn", "ruby.h")
|
80
76
|
have_const("RB_WARN_CATEGORY_DEPRECATED", "ruby.h")
|
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.
|
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
|
+
version: 3.1.3
|
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:
|
13
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: This library provides arbitrary-precision decimal floating-point number
|
16
16
|
class.
|
@@ -43,8 +43,9 @@ files:
|
|
43
43
|
homepage: https://github.com/ruby/bigdecimal
|
44
44
|
licenses:
|
45
45
|
- Ruby
|
46
|
+
- bsd-2-clause
|
46
47
|
metadata: {}
|
47
|
-
post_install_message:
|
48
|
+
post_install_message:
|
48
49
|
rdoc_options: []
|
49
50
|
require_paths:
|
50
51
|
- lib
|
@@ -59,8 +60,8 @@ 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
|
-
signing_key:
|
63
|
+
rubygems_version: 3.4.0.dev
|
64
|
+
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Arbitrary-precision decimal floating-point number library.
|
66
67
|
test_files: []
|