bigdecimal 3.0.2 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ #include <ruby/ruby.h>
2
+
3
+ #ifdef HAVE_RUBY_ATOMIC_H
4
+ # include <ruby/atomic.h>
5
+ #endif
6
+
7
+ #ifdef RUBY_ATOMIC_PTR_CAS
8
+ # define ATOMIC_PTR_CAS(var, old, new) RUBY_ATOMIC_PTR_CAS(var, old, new)
9
+ #endif
10
+
11
+ #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
12
+ /* GCC warns about unknown sanitizer, which is annoying. */
13
+ # undef NO_SANITIZE
14
+ # define NO_SANITIZE(x, y) \
15
+ _Pragma("GCC diagnostic push") \
16
+ _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
17
+ __attribute__((__no_sanitize__(x))) y; \
18
+ _Pragma("GCC diagnostic pop")
19
+ #endif
20
+
21
+ #undef strtod
22
+ #define strtod BigDecimal_strtod
23
+ #undef dtoa
24
+ #define dtoa BigDecimal_dtoa
25
+ #undef hdtoa
26
+ #define hdtoa BigDecimal_hdtoa
27
+ #include "missing/dtoa.c"
@@ -0,0 +1,196 @@
1
+ #ifndef MISSING_H
2
+ #define MISSING_H 1
3
+
4
+ #if defined(__cplusplus)
5
+ extern "C" {
6
+ #if 0
7
+ } /* satisfy cc-mode */
8
+ #endif
9
+ #endif
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
+ #ifndef RB_UNUSED_VAR
20
+ # if defined(_MSC_VER) && _MSC_VER >= 1911
21
+ # define RB_UNUSED_VAR(x) x [[maybe_unused]]
22
+
23
+ # elif defined(__has_cpp_attribute) && __has_cpp_attribute(maybe_unused)
24
+ # define RB_UNUSED_VAR(x) x [[maybe_unused]]
25
+
26
+ # elif defined(__has_c_attribute) && __has_c_attribute(maybe_unused)
27
+ # define RB_UNUSED_VAR(x) x [[maybe_unused]]
28
+
29
+ # elif defined(__GNUC__)
30
+ # define RB_UNUSED_VAR(x) x __attribute__ ((unused))
31
+
32
+ # else
33
+ # define RB_UNUSED_VAR(x) x
34
+ # endif
35
+ #endif /* RB_UNUSED_VAR */
36
+
37
+ #if defined(_MSC_VER) && _MSC_VER >= 1310
38
+ # define HAVE___ASSUME 1
39
+
40
+ #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1300
41
+ # define HAVE___ASSUME 1
42
+ #endif
43
+
44
+ #ifndef UNREACHABLE
45
+ # if __has_builtin(__builtin_unreachable)
46
+ # define UNREACHABLE __builtin_unreachable()
47
+
48
+ # elif defined(HAVE___ASSUME)
49
+ # define UNREACHABLE __assume(0)
50
+
51
+ # else
52
+ # define UNREACHABLE /* unreachable */
53
+ # endif
54
+ #endif /* UNREACHABLE */
55
+
56
+ /* bool */
57
+
58
+ #if defined(__bool_true_false_are_defined)
59
+ # /* Take that. */
60
+
61
+ #elif defined(HAVE_STDBOOL_H)
62
+ # 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
+ #endif
119
+
120
+ /* dtoa */
121
+ char *BigDecimal_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve);
122
+
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
+ /* complex */
150
+
151
+ #ifndef HAVE_RB_COMPLEX_REAL
152
+ static inline VALUE
153
+ rb_complex_real(VALUE cmp)
154
+ {
155
+ #ifdef RCOMPLEX
156
+ return RCOMPLEX(cmp)->real;
157
+ #else
158
+ return rb_funcall(cmp, rb_intern("real"), 0);
159
+ #endif
160
+ }
161
+ #endif
162
+
163
+ #ifndef HAVE_RB_COMPLEX_IMAG
164
+ static inline VALUE
165
+ rb_complex_imag(VALUE cmp)
166
+ {
167
+ # ifdef RCOMPLEX
168
+ return RCOMPLEX(cmp)->imag;
169
+ # else
170
+ return rb_funcall(cmp, rb_intern("imag"), 0);
171
+ # endif
172
+ }
173
+ #endif
174
+
175
+ /* st */
176
+
177
+ #ifndef ST2FIX
178
+ # undef RB_ST2FIX
179
+ # define RB_ST2FIX(h) LONG2FIX((long)(h))
180
+ # define ST2FIX(h) RB_ST2FIX(h)
181
+ #endif
182
+
183
+ /* warning */
184
+
185
+ #if !defined(HAVE_RB_CATEGORY_WARN) || !defined(HAVE_CONST_RB_WARN_CATEGORY_DEPRECATED)
186
+ # define rb_category_warn(category, ...) rb_warn(__VA_ARGS__)
187
+ #endif
188
+
189
+ #if defined(__cplusplus)
190
+ #if 0
191
+ { /* satisfy cc-mode */
192
+ #endif
193
+ } /* extern "C" { */
194
+ #endif
195
+
196
+ #endif /* MISSING_H */
@@ -0,0 +1,54 @@
1
+ #ifndef BIGDECIMAL_STATIC_ASSERT_H
2
+ #define BIGDECIMAL_STATIC_ASSERT_H
3
+
4
+ #include "feature.h"
5
+
6
+ #ifdef HAVE_RUBY_INTERNAL_STATIC_ASSERT_H
7
+ # include <ruby/internal/static_assert.h>
8
+ #endif
9
+
10
+ #ifdef RBIMPL_STATIC_ASSERT
11
+ # define STATIC_ASSERT RBIMPL_STATIC_ASSERT
12
+ #endif
13
+
14
+ #ifndef STATIC_ASSERT
15
+ # /* The following section is copied from CRuby's static_assert.h */
16
+
17
+ # if defined(__cplusplus) && defined(__cpp_static_assert)
18
+ # /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */
19
+ # define BIGDECIMAL_STATIC_ASSERT0 static_assert
20
+
21
+ # elif defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1600
22
+ # define BIGDECIMAL_STATIC_ASSERT0 static_assert
23
+
24
+ # elif defined(__INTEL_CXX11_MODE__)
25
+ # define BIGDECIMAL_STATIC_ASSERT0 static_assert
26
+
27
+ # elif defined(__cplusplus) && __cplusplus >= 201103L
28
+ # define BIGDECIMAL_STATIC_ASSERT0 static_assert
29
+
30
+ # elif defined(__cplusplus) && __has_extension(cxx_static_assert)
31
+ # define BIGDECIMAL_STATIC_ASSERT0 __extension__ static_assert
32
+
33
+ # elif defined(__STDC_VERSION__) && __has_extension(c_static_assert)
34
+ # define BIGDECIMAL_STATIC_ASSERT0 __extension__ _Static_assert
35
+
36
+ # elif defined(__STDC_VERSION__) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
37
+ # define BIGDECIMAL_STATIC_ASSERT0 __extension__ _Static_assert
38
+ #endif
39
+
40
+ # if defined(__DOXYGEN__)
41
+ # define STATIC_ASSERT static_assert
42
+
43
+ # elif defined(BIGDECIMAL_STATIC_ASSERT0)
44
+ # define STATIC_ASSERT(name, expr) \
45
+ BIGDECIMAL_STATIC_ASSERT0(expr, #name ": " #expr)
46
+
47
+ # else
48
+ # define STATIC_ASSERT(name, expr) \
49
+ typedef int static_assert_ ## name ## _check[1 - 2 * !(expr)]
50
+ # endif
51
+ #endif /* STATIC_ASSERT */
52
+
53
+
54
+ #endif /* BIGDECIMAL_STATIC_ASSERT_H */
@@ -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,17 +33,21 @@ 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
- def to_d(precision=Float::DIG+1)
50
+ def to_d(precision=0)
47
51
  BigDecimal(self, precision)
48
52
  end
49
53
  end
@@ -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,73 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigdecimal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
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-05-03 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: 12.3.3
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: 12.3.3
29
- - !ruby/object:Gem::Dependency
30
- name: rake-compiler
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: '0.9'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: '0.9'
43
- - !ruby/object:Gem::Dependency
44
- name: minitest
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "<"
48
- - !ruby/object:Gem::Version
49
- version: 5.0.0
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "<"
55
- - !ruby/object:Gem::Version
56
- version: 5.0.0
57
- - !ruby/object:Gem::Dependency
58
- name: pry
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: '0'
13
+ date: 2024-01-18 00:00:00.000000000 Z
14
+ dependencies: []
71
15
  description: This library provides arbitrary-precision decimal floating-point number
72
16
  class.
73
17
  email:
@@ -77,10 +21,17 @@ extensions:
77
21
  - ext/bigdecimal/extconf.rb
78
22
  extra_rdoc_files: []
79
23
  files:
24
+ - LICENSE
80
25
  - bigdecimal.gemspec
81
26
  - ext/bigdecimal/bigdecimal.c
82
27
  - ext/bigdecimal/bigdecimal.h
28
+ - ext/bigdecimal/bits.h
83
29
  - ext/bigdecimal/extconf.rb
30
+ - ext/bigdecimal/feature.h
31
+ - ext/bigdecimal/missing.c
32
+ - ext/bigdecimal/missing.h
33
+ - ext/bigdecimal/missing/dtoa.c
34
+ - ext/bigdecimal/static_assert.h
84
35
  - lib/bigdecimal.rb
85
36
  - lib/bigdecimal/jacobian.rb
86
37
  - lib/bigdecimal/ludcmp.rb
@@ -93,8 +44,9 @@ files:
93
44
  homepage: https://github.com/ruby/bigdecimal
94
45
  licenses:
95
46
  - Ruby
47
+ - BSD-2-Clause
96
48
  metadata: {}
97
- post_install_message:
49
+ post_install_message:
98
50
  rdoc_options: []
99
51
  require_paths:
100
52
  - lib
@@ -102,15 +54,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
54
  requirements:
103
55
  - - ">="
104
56
  - !ruby/object:Gem::Version
105
- version: 2.4.0
57
+ version: 2.5.0
106
58
  required_rubygems_version: !ruby/object:Gem::Requirement
107
59
  requirements:
108
60
  - - ">="
109
61
  - !ruby/object:Gem::Version
110
62
  version: '0'
111
63
  requirements: []
112
- rubygems_version: 3.2.3
113
- signing_key:
64
+ rubygems_version: 3.6.0.dev
65
+ signing_key:
114
66
  specification_version: 4
115
67
  summary: Arbitrary-precision decimal floating-point number library.
116
68
  test_files: []