bigdecimal 1.3.5 → 3.1.9

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.
@@ -0,0 +1,28 @@
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
+ y
20
+ #endif
21
+
22
+ #undef strtod
23
+ #define strtod BigDecimal_strtod
24
+ #undef dtoa
25
+ #define dtoa BigDecimal_dtoa
26
+ #undef hdtoa
27
+ #define hdtoa BigDecimal_hdtoa
28
+ #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 */
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: false
2
- #
2
+
3
+ require 'bigdecimal'
4
+
3
5
  # require 'bigdecimal/jacobian'
4
6
  #
5
7
  # Provides methods to compute the Jacobian matrix of a set of equations at a
@@ -40,8 +42,8 @@ module Jacobian
40
42
  end
41
43
 
42
44
 
43
- # Computes the derivative of f[i] at x[i].
44
- # 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+.
45
47
  def dfdxi(f,fx,x,i)
46
48
  nRetry = 0
47
49
  n = x.size
@@ -73,7 +75,7 @@ module Jacobian
73
75
  deriv
74
76
  end
75
77
 
76
- # 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+.
77
79
  def jacobian(f,fx,x)
78
80
  n = x.size
79
81
  dfdx = Array.new(n*n)
@@ -5,6 +5,7 @@
5
5
  # and provides BigDecimal#to_d and BigDecimal#to_digits.
6
6
  #++
7
7
 
8
+ require 'bigdecimal'
8
9
 
9
10
  class Integer < Numeric
10
11
  # call-seq:
@@ -17,7 +18,7 @@ class Integer < Numeric
17
18
  #
18
19
  # 42.to_d # => 0.42e2
19
20
  #
20
- # See also BigDecimal::new.
21
+ # See also Kernel.BigDecimal.
21
22
  #
22
23
  def to_d
23
24
  BigDecimal(self)
@@ -32,18 +33,22 @@ class Float < Numeric
32
33
  #
33
34
  # Returns the value of +float+ as a BigDecimal.
34
35
  # The +precision+ parameter is used to determine the number of
35
- # 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+.
36
40
  #
37
41
  # require 'bigdecimal'
38
42
  # require 'bigdecimal/util'
39
43
  #
40
44
  # 0.5.to_d # => 0.5e0
45
+ # 1.234.to_d # => 0.1234e1
41
46
  # 1.234.to_d(2) # => 0.12e1
42
47
  #
43
- # See also BigDecimal::new.
48
+ # See also Kernel.BigDecimal.
44
49
  #
45
- def to_d(precision=nil)
46
- BigDecimal(self, precision || Float::DIG)
50
+ def to_d(precision=0)
51
+ BigDecimal(self, precision)
47
52
  end
48
53
  end
49
54
 
@@ -62,14 +67,10 @@ class String
62
67
  # "123.45e1".to_d # => 0.12345e4
63
68
  # "45.67 degrees".to_d # => 0.4567e2
64
69
  #
65
- # See also BigDecimal::new.
70
+ # See also Kernel.BigDecimal.
66
71
  #
67
72
  def to_d
68
- begin
69
- BigDecimal(self)
70
- rescue ArgumentError
71
- BigDecimal(0)
72
- end
73
+ BigDecimal.interpret_loosely(self)
73
74
  end
74
75
  end
75
76
 
@@ -126,7 +127,7 @@ class Rational < Numeric
126
127
  #
127
128
  # Rational(22, 7).to_d(3) # => 0.314e1
128
129
  #
129
- # See also BigDecimal::new.
130
+ # See also Kernel.BigDecimal.
130
131
  #
131
132
  def to_d(precision)
132
133
  BigDecimal(self, precision)
@@ -134,6 +135,39 @@ class Rational < Numeric
134
135
  end
135
136
 
136
137
 
138
+ class Complex < Numeric
139
+ # call-seq:
140
+ # cmp.to_d -> bigdecimal
141
+ # cmp.to_d(precision) -> bigdecimal
142
+ #
143
+ # Returns the value as a BigDecimal.
144
+ #
145
+ # The +precision+ parameter is required for a rational complex number.
146
+ # This parameter is used to determine the number of significant digits
147
+ # for the result.
148
+ #
149
+ # require 'bigdecimal'
150
+ # require 'bigdecimal/util'
151
+ #
152
+ # Complex(0.1234567, 0).to_d(4) # => 0.1235e0
153
+ # Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
154
+ #
155
+ # See also Kernel.BigDecimal.
156
+ #
157
+ def to_d(*args)
158
+ BigDecimal(self) unless self.imag.zero? # to raise error
159
+
160
+ if args.length == 0
161
+ case self.real
162
+ when Rational
163
+ BigDecimal(self.real) # to raise error
164
+ end
165
+ end
166
+ self.real.to_d(*args)
167
+ end
168
+ end
169
+
170
+
137
171
  class NilClass
138
172
  # call-seq:
139
173
  # nil.to_d -> bigdecimal
data/lib/bigdecimal.rb ADDED
@@ -0,0 +1,5 @@
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,87 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigdecimal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 3.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Murata
8
8
  - Zachary Scott
9
9
  - Shigeo Kobayashi
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2018-06-15 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: '10.0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - "~>"
27
- - !ruby/object:Gem::Version
28
- version: '10.0'
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: rake-compiler-dock
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.6.1
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.6.1
57
- - !ruby/object:Gem::Dependency
58
- name: minitest
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "<"
62
- - !ruby/object:Gem::Version
63
- version: 5.0.0
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "<"
69
- - !ruby/object:Gem::Version
70
- version: 5.0.0
71
- - !ruby/object:Gem::Dependency
72
- name: pry
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
12
+ date: 2024-12-25 00:00:00.000000000 Z
13
+ dependencies: []
85
14
  description: This library provides arbitrary-precision decimal floating-point number
86
15
  class.
87
16
  email:
@@ -91,11 +20,18 @@ extensions:
91
20
  - ext/bigdecimal/extconf.rb
92
21
  extra_rdoc_files: []
93
22
  files:
23
+ - LICENSE
94
24
  - bigdecimal.gemspec
95
25
  - ext/bigdecimal/bigdecimal.c
96
26
  - ext/bigdecimal/bigdecimal.h
97
- - ext/bigdecimal/depend
27
+ - ext/bigdecimal/bits.h
98
28
  - ext/bigdecimal/extconf.rb
29
+ - ext/bigdecimal/feature.h
30
+ - ext/bigdecimal/missing.c
31
+ - ext/bigdecimal/missing.h
32
+ - ext/bigdecimal/missing/dtoa.c
33
+ - ext/bigdecimal/static_assert.h
34
+ - lib/bigdecimal.rb
99
35
  - lib/bigdecimal/jacobian.rb
100
36
  - lib/bigdecimal/ludcmp.rb
101
37
  - lib/bigdecimal/math.rb
@@ -106,9 +42,10 @@ files:
106
42
  - sample/pi.rb
107
43
  homepage: https://github.com/ruby/bigdecimal
108
44
  licenses:
109
- - ruby
110
- metadata: {}
111
- post_install_message:
45
+ - Ruby
46
+ - BSD-2-Clause
47
+ metadata:
48
+ changelog_uri: https://github.com/ruby/bigdecimal/blob/master/CHANGES.md
112
49
  rdoc_options: []
113
50
  require_paths:
114
51
  - lib
@@ -116,16 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
53
  requirements:
117
54
  - - ">="
118
55
  - !ruby/object:Gem::Version
119
- version: '0'
56
+ version: 2.5.0
120
57
  required_rubygems_version: !ruby/object:Gem::Requirement
121
58
  requirements:
122
59
  - - ">="
123
60
  - !ruby/object:Gem::Version
124
61
  version: '0'
125
62
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.6
128
- signing_key:
63
+ rubygems_version: 3.6.2
129
64
  specification_version: 4
130
65
  summary: Arbitrary-precision decimal floating-point number library.
131
66
  test_files: []
@@ -1,13 +0,0 @@
1
- # AUTOGENERATED DEPENDENCIES START
2
- bigdecimal.o: $(RUBY_EXTCONF_H)
3
- bigdecimal.o: $(arch_hdrdir)/ruby/config.h
4
- bigdecimal.o: $(hdrdir)/ruby/defines.h
5
- bigdecimal.o: $(hdrdir)/ruby/intern.h
6
- bigdecimal.o: $(hdrdir)/ruby/missing.h
7
- bigdecimal.o: $(hdrdir)/ruby/ruby.h
8
- bigdecimal.o: $(hdrdir)/ruby/st.h
9
- bigdecimal.o: $(hdrdir)/ruby/subst.h
10
- bigdecimal.o: $(hdrdir)/ruby/util.h
11
- bigdecimal.o: bigdecimal.c
12
- bigdecimal.o: bigdecimal.h
13
- # AUTOGENERATED DEPENDENCIES END