bigdecimal 3.2.2 → 4.0.0
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.
- checksums.yaml +4 -4
- data/ext/bigdecimal/bigdecimal.c +734 -2289
- data/ext/bigdecimal/bigdecimal.h +4 -25
- data/ext/bigdecimal/bits.h +3 -0
- data/ext/bigdecimal/extconf.rb +3 -7
- data/ext/bigdecimal/missing.h +1 -93
- data/lib/bigdecimal/jacobian.rb +2 -0
- data/lib/bigdecimal/ludcmp.rb +2 -0
- data/lib/bigdecimal/math.rb +789 -71
- data/lib/bigdecimal/newton.rb +2 -0
- data/lib/bigdecimal/util.rb +15 -14
- data/lib/bigdecimal.rb +355 -0
- metadata +2 -2
data/ext/bigdecimal/bigdecimal.h
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
# include <float.h>
|
|
18
18
|
#endif
|
|
19
19
|
|
|
20
|
-
#
|
|
20
|
+
#if defined(HAVE_INT64_T) && !defined(BIGDECIMAL_USE_DECDIG_UINT16_T)
|
|
21
21
|
# define DECDIG uint32_t
|
|
22
22
|
# define DECDIG_DBL uint64_t
|
|
23
23
|
# define DECDIG_DBL_SIGNED int64_t
|
|
@@ -167,7 +167,6 @@ enum rbd_rounding_mode {
|
|
|
167
167
|
* r = 0.xxxxxxxxx *BASE**exponent
|
|
168
168
|
*/
|
|
169
169
|
typedef struct {
|
|
170
|
-
VALUE obj; /* Back pointer(VALUE) for Ruby object. */
|
|
171
170
|
size_t MaxPrec; /* Maximum precision size */
|
|
172
171
|
/* This is the actual size of frac[] */
|
|
173
172
|
/*(frac[0] to frac[MaxPrec] are available). */
|
|
@@ -195,13 +194,7 @@ typedef struct {
|
|
|
195
194
|
* ------------------
|
|
196
195
|
*/
|
|
197
196
|
|
|
198
|
-
VP_EXPORT Real *VpNewRbClass(size_t mx, char const *str, VALUE klass, bool strict_p, bool raise_exception);
|
|
199
|
-
|
|
200
|
-
VP_EXPORT Real *VpCreateRbObject(size_t mx, const char *str, bool raise_exception);
|
|
201
|
-
|
|
202
197
|
#define VpBaseFig() BIGDECIMAL_COMPONENT_FIGURES
|
|
203
|
-
#define VpDblFig() BIGDECIMAL_DOUBLE_FIGURES
|
|
204
|
-
#define VpBaseVal() BIGDECIMAL_BASE
|
|
205
198
|
|
|
206
199
|
/* Zero,Inf,NaN (isinf(),isnan() used to check) */
|
|
207
200
|
VP_EXPORT double VpGetDoubleNaN(void);
|
|
@@ -211,7 +204,7 @@ VP_EXPORT double VpGetDoubleNegZero(void);
|
|
|
211
204
|
|
|
212
205
|
/* These 2 functions added at v1.1.7 */
|
|
213
206
|
VP_EXPORT size_t VpGetPrecLimit(void);
|
|
214
|
-
VP_EXPORT
|
|
207
|
+
VP_EXPORT void VpSetPrecLimit(size_t n);
|
|
215
208
|
|
|
216
209
|
/* Round mode */
|
|
217
210
|
VP_EXPORT int VpIsRoundMode(unsigned short n);
|
|
@@ -219,16 +212,14 @@ VP_EXPORT unsigned short VpGetRoundMode(void);
|
|
|
219
212
|
VP_EXPORT unsigned short VpSetRoundMode(unsigned short n);
|
|
220
213
|
|
|
221
214
|
VP_EXPORT int VpException(unsigned short f,const char *str,int always);
|
|
222
|
-
#if 0 /* unused */
|
|
223
|
-
VP_EXPORT int VpIsNegDoubleZero(double v);
|
|
224
|
-
#endif
|
|
225
215
|
VP_EXPORT size_t VpNumOfChars(Real *vp,const char *pszFmt);
|
|
226
216
|
VP_EXPORT size_t VpInit(DECDIG BaseVal);
|
|
227
|
-
VP_EXPORT Real *VpAlloc(
|
|
217
|
+
VP_EXPORT Real *VpAlloc(const char *szVal, int strict_p, int exc);
|
|
228
218
|
VP_EXPORT size_t VpAsgn(Real *c, Real *a, int isw);
|
|
229
219
|
VP_EXPORT size_t VpAddSub(Real *c,Real *a,Real *b,int operation);
|
|
230
220
|
VP_EXPORT size_t VpMult(Real *c,Real *a,Real *b);
|
|
231
221
|
VP_EXPORT size_t VpDivd(Real *c,Real *r,Real *a,Real *b);
|
|
222
|
+
VP_EXPORT int VpNmlz(Real *a);
|
|
232
223
|
VP_EXPORT int VpComp(Real *a,Real *b);
|
|
233
224
|
VP_EXPORT ssize_t VpExponent10(Real *a);
|
|
234
225
|
VP_EXPORT void VpSzMantissa(Real *a, char *buf, size_t bufsize);
|
|
@@ -237,17 +228,10 @@ VP_EXPORT void VpToString(Real *a, char *buf, size_t bufsize, size_t fFmt, int f
|
|
|
237
228
|
VP_EXPORT void VpToFString(Real *a, char *buf, size_t bufsize, size_t fFmt, int fPlus);
|
|
238
229
|
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);
|
|
239
230
|
VP_EXPORT int VpVtoD(double *d, SIGNED_VALUE *e, Real *m);
|
|
240
|
-
VP_EXPORT void VpDtoV(Real *m,double d);
|
|
241
|
-
#if 0 /* unused */
|
|
242
|
-
VP_EXPORT void VpItoV(Real *m,S_INT ival);
|
|
243
|
-
#endif
|
|
244
|
-
VP_EXPORT int VpSqrt(Real *y,Real *x);
|
|
245
231
|
VP_EXPORT int VpActiveRound(Real *y, Real *x, unsigned short f, ssize_t il);
|
|
246
232
|
VP_EXPORT int VpMidRound(Real *y, unsigned short f, ssize_t nf);
|
|
247
233
|
VP_EXPORT int VpLeftRound(Real *y, unsigned short f, ssize_t nf);
|
|
248
234
|
VP_EXPORT void VpFrac(Real *y, Real *x);
|
|
249
|
-
VP_EXPORT int VpPowerByInt(Real *y, Real *x, SIGNED_VALUE n);
|
|
250
|
-
#define VpPower VpPowerByInt
|
|
251
235
|
|
|
252
236
|
/* VP constants */
|
|
253
237
|
VP_EXPORT Real *VpOne(void);
|
|
@@ -261,10 +245,6 @@ VP_EXPORT Real *VpOne(void);
|
|
|
261
245
|
#define Max(a, b) (((a)>(b))?(a):(b))
|
|
262
246
|
#define Min(a, b) (((a)>(b))?(b):(a))
|
|
263
247
|
|
|
264
|
-
#define VpMaxPrec(a) ((a)->MaxPrec)
|
|
265
|
-
#define VpPrec(a) ((a)->Prec)
|
|
266
|
-
#define VpGetFlag(a) ((a)->flag)
|
|
267
|
-
|
|
268
248
|
/* Sign */
|
|
269
249
|
|
|
270
250
|
/* VpGetSign(a) returns 1,-1 if a>0,a<0 respectively */
|
|
@@ -299,7 +279,6 @@ VP_EXPORT Real *VpOne(void);
|
|
|
299
279
|
#define VpSetInf(a,s) (void)(((s)>0)?VpSetPosInf(a):VpSetNegInf(a))
|
|
300
280
|
#define VpHasVal(a) (a->frac[0])
|
|
301
281
|
#define VpIsOne(a) ((a->Prec==1)&&(a->frac[0]==1)&&(a->exponent==1))
|
|
302
|
-
#define VpExponent(a) (a->exponent)
|
|
303
282
|
#ifdef BIGDECIMAL_DEBUG
|
|
304
283
|
int VpVarCheck(Real * v);
|
|
305
284
|
#endif /* BIGDECIMAL_DEBUG */
|
data/ext/bigdecimal/bits.h
CHANGED
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
|
|
27
27
|
((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
|
|
28
28
|
|
|
29
|
+
#define ADD_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
|
|
30
|
+
((a) > 0) == ((b) > 0) && ((a) > 0 ? (max) - (a) < (b) : (min) - (a) > (b)))
|
|
31
|
+
|
|
29
32
|
#ifdef HAVE_UINT128_T
|
|
30
33
|
# define bit_length(x) \
|
|
31
34
|
(unsigned int) \
|
data/ext/bigdecimal/extconf.rb
CHANGED
|
@@ -36,17 +36,10 @@ if have_header("intrin.h")
|
|
|
36
36
|
have_func("_BitScanReverse64", "intrin.h")
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
have_func("labs", "stdlib.h")
|
|
40
|
-
have_func("llabs", "stdlib.h")
|
|
41
|
-
have_func("finite", "math.h")
|
|
42
|
-
have_func("isfinite", "math.h")
|
|
43
|
-
|
|
44
39
|
have_header("ruby/atomic.h")
|
|
45
40
|
have_header("ruby/internal/has/builtin.h")
|
|
46
41
|
have_header("ruby/internal/static_assert.h")
|
|
47
42
|
|
|
48
|
-
have_func("rb_rational_num", "ruby.h")
|
|
49
|
-
have_func("rb_rational_den", "ruby.h")
|
|
50
43
|
have_func("rb_complex_real", "ruby.h")
|
|
51
44
|
have_func("rb_complex_imag", "ruby.h")
|
|
52
45
|
have_func("rb_opts_exception_p", "ruby.h")
|
|
@@ -59,6 +52,9 @@ else
|
|
|
59
52
|
bigdecimal_rb = "$(srcdir)/../../lib/bigdecimal.rb"
|
|
60
53
|
end
|
|
61
54
|
|
|
55
|
+
$defs.push '-DBIGDECIMAL_USE_DECDIG_UINT16_T' if ENV['BIGDECIMAL_USE_DECDIG_UINT16_T'] == 'true'
|
|
56
|
+
$defs.push '-DBIGDECIMAL_USE_VP_TEST_METHODS' if ENV['BIGDECIMAL_USE_VP_TEST_METHODS'] == 'true'
|
|
57
|
+
|
|
62
58
|
create_makefile('bigdecimal') {|mf|
|
|
63
59
|
mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n"
|
|
64
60
|
}
|
data/ext/bigdecimal/missing.h
CHANGED
|
@@ -8,14 +8,6 @@ extern "C" {
|
|
|
8
8
|
#endif
|
|
9
9
|
#endif
|
|
10
10
|
|
|
11
|
-
#ifdef HAVE_STDLIB_H
|
|
12
|
-
# include <stdlib.h>
|
|
13
|
-
#endif
|
|
14
|
-
|
|
15
|
-
#ifdef HAVE_MATH_H
|
|
16
|
-
# include <math.h>
|
|
17
|
-
#endif
|
|
18
|
-
|
|
19
11
|
#ifndef RB_UNUSED_VAR
|
|
20
12
|
# if defined(_MSC_VER) && _MSC_VER >= 1911
|
|
21
13
|
# define RB_UNUSED_VAR(x) x [[maybe_unused]]
|
|
@@ -55,97 +47,13 @@ extern "C" {
|
|
|
55
47
|
|
|
56
48
|
/* bool */
|
|
57
49
|
|
|
58
|
-
#
|
|
59
|
-
# /* Take that. */
|
|
60
|
-
|
|
61
|
-
#elif defined(HAVE_STDBOOL_H)
|
|
50
|
+
#ifndef __bool_true_false_are_defined
|
|
62
51
|
# include <stdbool.h>
|
|
63
|
-
|
|
64
|
-
#else
|
|
65
|
-
typedef unsigned char _Bool;
|
|
66
|
-
# define bool _Bool
|
|
67
|
-
# define true ((_Bool)+1)
|
|
68
|
-
# define false ((_Bool)-1)
|
|
69
|
-
# define __bool_true_false_are_defined
|
|
70
|
-
#endif
|
|
71
|
-
|
|
72
|
-
/* abs */
|
|
73
|
-
|
|
74
|
-
#ifndef HAVE_LABS
|
|
75
|
-
static inline long
|
|
76
|
-
labs(long const x)
|
|
77
|
-
{
|
|
78
|
-
if (x < 0) return -x;
|
|
79
|
-
return x;
|
|
80
|
-
}
|
|
81
|
-
#endif
|
|
82
|
-
|
|
83
|
-
#ifndef HAVE_LLABS
|
|
84
|
-
static inline LONG_LONG
|
|
85
|
-
llabs(LONG_LONG const x)
|
|
86
|
-
{
|
|
87
|
-
if (x < 0) return -x;
|
|
88
|
-
return x;
|
|
89
|
-
}
|
|
90
|
-
#endif
|
|
91
|
-
|
|
92
|
-
#ifdef vabs
|
|
93
|
-
# undef vabs
|
|
94
|
-
#endif
|
|
95
|
-
#if SIZEOF_VALUE <= SIZEOF_INT
|
|
96
|
-
# define vabs abs
|
|
97
|
-
#elif SIZEOF_VALUE <= SIZEOF_LONG
|
|
98
|
-
# define vabs labs
|
|
99
|
-
#elif SIZEOF_VALUE <= SIZEOF_LONG_LONG
|
|
100
|
-
# define vabs llabs
|
|
101
|
-
#endif
|
|
102
|
-
|
|
103
|
-
/* finite */
|
|
104
|
-
|
|
105
|
-
#ifndef HAVE_FINITE
|
|
106
|
-
static int
|
|
107
|
-
finite(double)
|
|
108
|
-
{
|
|
109
|
-
return !isnan(n) && !isinf(n);
|
|
110
|
-
}
|
|
111
|
-
#endif
|
|
112
|
-
|
|
113
|
-
#ifndef isfinite
|
|
114
|
-
# ifndef HAVE_ISFINITE
|
|
115
|
-
# define HAVE_ISFINITE 1
|
|
116
|
-
# define isfinite(x) finite(x)
|
|
117
|
-
# endif
|
|
118
52
|
#endif
|
|
119
53
|
|
|
120
54
|
/* dtoa */
|
|
121
55
|
char *BigDecimal_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve);
|
|
122
56
|
|
|
123
|
-
/* rational */
|
|
124
|
-
|
|
125
|
-
#ifndef HAVE_RB_RATIONAL_NUM
|
|
126
|
-
static inline VALUE
|
|
127
|
-
rb_rational_num(VALUE rat)
|
|
128
|
-
{
|
|
129
|
-
#ifdef RRATIONAL
|
|
130
|
-
return RRATIONAL(rat)->num;
|
|
131
|
-
#else
|
|
132
|
-
return rb_funcall(rat, rb_intern("numerator"), 0);
|
|
133
|
-
#endif
|
|
134
|
-
}
|
|
135
|
-
#endif
|
|
136
|
-
|
|
137
|
-
#ifndef HAVE_RB_RATIONAL_DEN
|
|
138
|
-
static inline VALUE
|
|
139
|
-
rb_rational_den(VALUE rat)
|
|
140
|
-
{
|
|
141
|
-
#ifdef RRATIONAL
|
|
142
|
-
return RRATIONAL(rat)->den;
|
|
143
|
-
#else
|
|
144
|
-
return rb_funcall(rat, rb_intern("denominator"), 0);
|
|
145
|
-
#endif
|
|
146
|
-
}
|
|
147
|
-
#endif
|
|
148
|
-
|
|
149
57
|
/* complex */
|
|
150
58
|
|
|
151
59
|
#ifndef HAVE_RB_COMPLEX_REAL
|
data/lib/bigdecimal/jacobian.rb
CHANGED