bigdecimal 1.3.1 → 1.3.2
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 -1
- data/ext/bigdecimal/bigdecimal.c +54 -19
- data/ext/bigdecimal/bigdecimal.h +2 -0
- data/ext/bigdecimal/extconf.rb +0 -9
- data/lib/bigdecimal/util.rb +47 -50
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e74979e928a1faa6ecca707c8d405be6e4c0b6d5
|
4
|
+
data.tar.gz: f8fb2859efdaa6a9ff49ae0d9d0cc2471ff2f89e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 585f1a41327c0265d6dbe79ea5934d92381d75c07f3305fe284d226f7e3315d15db6003441356b2e374ef2cd6909f2d5ce64df23604e1763f1d1340690ccc739
|
7
|
+
data.tar.gz: ccf79300c8b45bd8bed8f240f72ee6aa43c14bec8944e1b6871fdba9639d40b53da6a4a31072f05cee66703f57102946fec9e7cfb161d8ea10bb200e185c166f
|
data/bigdecimal.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
_VERSION = '1.3.
|
2
|
+
_VERSION = '1.3.2'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "bigdecimal"
|
@@ -33,4 +33,5 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.add_development_dependency "rake", "~> 10.0"
|
34
34
|
s.add_development_dependency "rake-compiler", "~> 0.9"
|
35
35
|
s.add_development_dependency "minitest", "~> 4.7.5"
|
36
|
+
s.add_development_dependency "pry"
|
36
37
|
end
|
data/ext/bigdecimal/bigdecimal.c
CHANGED
@@ -231,6 +231,7 @@ static inline VALUE BigDecimal_div2(VALUE, VALUE, VALUE);
|
|
231
231
|
static Real*
|
232
232
|
GetVpValueWithPrec(VALUE v, long prec, int must)
|
233
233
|
{
|
234
|
+
ENTER(1);
|
234
235
|
Real *pv;
|
235
236
|
VALUE num, bg;
|
236
237
|
char szD[128];
|
@@ -295,6 +296,7 @@ again:
|
|
295
296
|
|
296
297
|
case T_BIGNUM:
|
297
298
|
bg = rb_big2str(v, 10);
|
299
|
+
PUSH(bg);
|
298
300
|
return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
|
299
301
|
RSTRING_PTR(bg));
|
300
302
|
default:
|
@@ -1318,25 +1320,14 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)
|
|
1318
1320
|
return Qnil;
|
1319
1321
|
}
|
1320
1322
|
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
*
|
1330
|
-
* digits:: If specified and less than the number of significant digits of the
|
1331
|
-
* result, the result is rounded to that number of digits, according
|
1332
|
-
* to BigDecimal.mode.
|
1333
|
-
*
|
1334
|
-
* If digits is 0, the result is the same as the / operator. If not, the
|
1335
|
-
* result is an integer BigDecimal, by analogy with Float#div.
|
1336
|
-
*
|
1337
|
-
* The alias quo is provided since <code>div(value, 0)</code> is the same as
|
1338
|
-
* computing the quotient; see BigDecimal#divmod.
|
1339
|
-
*/
|
1323
|
+
/* call-seq:
|
1324
|
+
* a / b -> bigdecimal
|
1325
|
+
* quo(value) -> bigdecimal
|
1326
|
+
*
|
1327
|
+
* Divide by the specified value.
|
1328
|
+
*
|
1329
|
+
* See BigDecimal#div.
|
1330
|
+
*/
|
1340
1331
|
static VALUE
|
1341
1332
|
BigDecimal_div(VALUE self, VALUE r)
|
1342
1333
|
/* For c = self/r: with round operation */
|
@@ -1602,6 +1593,37 @@ BigDecimal_div2(VALUE self, VALUE b, VALUE n)
|
|
1602
1593
|
}
|
1603
1594
|
}
|
1604
1595
|
|
1596
|
+
/*
|
1597
|
+
* Document-method: BigDecimal#div
|
1598
|
+
*
|
1599
|
+
* call-seq:
|
1600
|
+
* div(value, digits) -> bigdecimal or integer
|
1601
|
+
*
|
1602
|
+
* Divide by the specified value.
|
1603
|
+
*
|
1604
|
+
* digits:: If specified and less than the number of significant digits of the
|
1605
|
+
* result, the result is rounded to that number of digits, according
|
1606
|
+
* to BigDecimal.mode.
|
1607
|
+
*
|
1608
|
+
* If digits is 0, the result is the same as for the / operator
|
1609
|
+
* or #quo.
|
1610
|
+
*
|
1611
|
+
* If digits is not specified, the result is an integer,
|
1612
|
+
* by analogy with Float#div; see also BigDecimal#divmod.
|
1613
|
+
*
|
1614
|
+
* Examples:
|
1615
|
+
*
|
1616
|
+
* a = BigDecimal("4")
|
1617
|
+
* b = BigDecimal("3")
|
1618
|
+
*
|
1619
|
+
* a.div(b, 3) # => 0.133e1
|
1620
|
+
*
|
1621
|
+
* a.div(b, 0) # => 0.1333333333333333333e1
|
1622
|
+
* a / b # => 0.1333333333333333333e1
|
1623
|
+
* a.quo(b) # => 0.1333333333333333333e1
|
1624
|
+
*
|
1625
|
+
* a.div(b) # => 1
|
1626
|
+
*/
|
1605
1627
|
static VALUE
|
1606
1628
|
BigDecimal_div3(int argc, VALUE *argv, VALUE self)
|
1607
1629
|
{
|
@@ -3193,6 +3215,19 @@ get_vp_value:
|
|
3193
3215
|
* Note also that in mathematics, there is no particular concept of negative
|
3194
3216
|
* or positive zero; true mathematical zero has no sign.
|
3195
3217
|
*
|
3218
|
+
* == bigdecimal/util
|
3219
|
+
*
|
3220
|
+
* When you require +bigdecimal/util+, the #to_d method will be
|
3221
|
+
* available on BigDecimal and the native Integer, Float, Rational,
|
3222
|
+
* and String classes:
|
3223
|
+
*
|
3224
|
+
* require 'bigdecimal/util'
|
3225
|
+
*
|
3226
|
+
* 42.to_d # => 0.42e2
|
3227
|
+
* 0.5.to_d # => 0.5e0
|
3228
|
+
* (2/3r).to_d(3) # => 0.667e0
|
3229
|
+
* "0.5".to_d # => 0.5e0
|
3230
|
+
*
|
3196
3231
|
* == License
|
3197
3232
|
*
|
3198
3233
|
* Copyright (C) 2002 by Shigeo Kobayashi <shigeo@tinyforest.gr.jp>.
|
data/ext/bigdecimal/bigdecimal.h
CHANGED
data/ext/bigdecimal/extconf.rb
CHANGED
@@ -15,12 +15,3 @@ have_func("rb_array_const_ptr", "ruby.h")
|
|
15
15
|
have_func("rb_sym2str", "ruby.h")
|
16
16
|
|
17
17
|
create_makefile('bigdecimal')
|
18
|
-
|
19
|
-
# Add additional dependencies
|
20
|
-
open('Makefile', 'a') do |io|
|
21
|
-
if RUBY_VERSION >= '2.4'
|
22
|
-
io.puts <<-MAKEFILE
|
23
|
-
bigdecimal.o: $(hdrdir)/ruby/backward.h
|
24
|
-
MAKEFILE
|
25
|
-
end
|
26
|
-
end
|
data/lib/bigdecimal/util.rb
CHANGED
@@ -1,66 +1,68 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
#
|
3
|
+
#--
|
3
4
|
# bigdecimal/util extends various native classes to provide the #to_d method,
|
4
5
|
# and provides BigDecimal#to_d and BigDecimal#to_digits.
|
6
|
+
#++
|
5
7
|
|
6
8
|
|
7
|
-
# bigdecimal/util extends the native Integer class to provide the #to_d method.
|
8
|
-
#
|
9
|
-
# When you require 'bigdecimal/util' in your application, this method will
|
10
|
-
# be available on Integer objects.
|
11
9
|
class Integer < Numeric
|
12
10
|
# call-seq:
|
13
11
|
# int.to_d -> bigdecimal
|
14
12
|
#
|
15
|
-
#
|
13
|
+
# Returns the value of +int+ as a BigDecimal.
|
16
14
|
#
|
17
15
|
# require 'bigdecimal'
|
18
16
|
# require 'bigdecimal/util'
|
19
17
|
#
|
20
|
-
# 42.to_d
|
21
|
-
#
|
18
|
+
# 42.to_d # => 0.42e2
|
19
|
+
#
|
20
|
+
# See also BigDecimal::new.
|
22
21
|
#
|
23
22
|
def to_d
|
24
23
|
BigDecimal(self)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
#
|
30
|
-
# When you require 'bigdecimal/util' in your application, this method will be
|
31
|
-
# available on Float objects.
|
27
|
+
|
32
28
|
class Float < Numeric
|
33
29
|
# call-seq:
|
34
|
-
#
|
30
|
+
# float.to_d -> bigdecimal
|
31
|
+
# float.to_d(precision) -> bigdecimal
|
35
32
|
#
|
36
|
-
#
|
33
|
+
# Returns the value of +float+ as a BigDecimal.
|
34
|
+
# The +precision+ parameter is used to determine the number of
|
35
|
+
# significant digits for the result (the default is Float::DIG).
|
37
36
|
#
|
38
37
|
# require 'bigdecimal'
|
39
38
|
# require 'bigdecimal/util'
|
40
39
|
#
|
41
|
-
# 0.5.to_d
|
42
|
-
# # => 0.
|
40
|
+
# 0.5.to_d # => 0.5e0
|
41
|
+
# 1.234.to_d(2) # => 0.12e1
|
42
|
+
#
|
43
|
+
# See also BigDecimal::new.
|
43
44
|
#
|
44
45
|
def to_d(precision=nil)
|
45
46
|
BigDecimal(self, precision || Float::DIG)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
-
#
|
51
|
-
# When you require 'bigdecimal/util' in your application, this method will be
|
52
|
-
# available on String objects.
|
50
|
+
|
53
51
|
class String
|
54
52
|
# call-seq:
|
55
|
-
#
|
53
|
+
# str.to_d -> bigdecimal
|
56
54
|
#
|
57
|
-
#
|
55
|
+
# Returns the result of interpreting leading characters in +str+
|
56
|
+
# as a BigDecimal.
|
58
57
|
#
|
59
58
|
# require 'bigdecimal'
|
60
59
|
# require 'bigdecimal/util'
|
61
60
|
#
|
62
|
-
# "0.5".to_d
|
63
|
-
# # => 0.
|
61
|
+
# "0.5".to_d # => 0.5e0
|
62
|
+
# "123.45e1".to_d # => 0.12345e4
|
63
|
+
# "45.67 degrees".to_d # => 0.4567e2
|
64
|
+
#
|
65
|
+
# See also BigDecimal::new.
|
64
66
|
#
|
65
67
|
def to_d
|
66
68
|
begin
|
@@ -71,11 +73,7 @@ class String
|
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
|
-
|
75
|
-
# #to_d methods.
|
76
|
-
#
|
77
|
-
# When you require 'bigdecimal/util' in your application, these methods will be
|
78
|
-
# available on BigDecimal objects.
|
76
|
+
|
79
77
|
class BigDecimal < Numeric
|
80
78
|
# call-seq:
|
81
79
|
# a.to_digits -> string
|
@@ -83,12 +81,11 @@ class BigDecimal < Numeric
|
|
83
81
|
# Converts a BigDecimal to a String of the form "nnnnnn.mmm".
|
84
82
|
# This method is deprecated; use BigDecimal#to_s("F") instead.
|
85
83
|
#
|
86
|
-
# require 'bigdecimal'
|
87
84
|
# require 'bigdecimal/util'
|
88
85
|
#
|
89
86
|
# d = BigDecimal.new("3.14")
|
90
|
-
# d.to_digits
|
91
|
-
#
|
87
|
+
# d.to_digits # => "3.14"
|
88
|
+
#
|
92
89
|
def to_digits
|
93
90
|
if self.nan? || self.infinite? || self.zero?
|
94
91
|
self.to_s
|
@@ -103,35 +100,35 @@ class BigDecimal < Numeric
|
|
103
100
|
# a.to_d -> bigdecimal
|
104
101
|
#
|
105
102
|
# Returns self.
|
103
|
+
#
|
104
|
+
# require 'bigdecimal/util'
|
105
|
+
#
|
106
|
+
# d = BigDecimal.new("3.14")
|
107
|
+
# d.to_d # => 0.314e1
|
108
|
+
#
|
106
109
|
def to_d
|
107
110
|
self
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
111
|
-
|
112
|
-
#
|
113
|
-
# When you require 'bigdecimal/util' in your application, this method will be
|
114
|
-
# available on Rational objects.
|
114
|
+
|
115
115
|
class Rational < Numeric
|
116
116
|
# call-seq:
|
117
|
-
#
|
117
|
+
# rat.to_d(precision) -> bigdecimal
|
118
118
|
#
|
119
|
-
#
|
119
|
+
# Returns the value as a BigDecimal.
|
120
120
|
#
|
121
|
-
# The required +precision+ parameter is used to determine the
|
122
|
-
# significant digits for the result.
|
123
|
-
#
|
124
|
-
#
|
121
|
+
# The required +precision+ parameter is used to determine the number of
|
122
|
+
# significant digits for the result.
|
123
|
+
#
|
124
|
+
# require 'bigdecimal'
|
125
|
+
# require 'bigdecimal/util'
|
126
|
+
#
|
127
|
+
# Rational(22, 7).to_d(3) # => 0.314e1
|
128
|
+
#
|
129
|
+
# See also BigDecimal::new.
|
125
130
|
#
|
126
|
-
# r = (22/7.0).to_r
|
127
|
-
# # => (7077085128725065/2251799813685248)
|
128
|
-
# r.to_d(3)
|
129
|
-
# # => 0.314e1
|
130
131
|
def to_d(precision)
|
131
|
-
|
132
|
-
raise ArgumentError, "negative precision"
|
133
|
-
end
|
134
|
-
num = self.numerator
|
135
|
-
BigDecimal(num).div(self.denominator, precision)
|
132
|
+
BigDecimal(self, precision)
|
136
133
|
end
|
137
134
|
end
|
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: 1.3.
|
4
|
+
version: 1.3.2
|
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: 2017-
|
13
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -54,6 +54,20 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 4.7.5
|
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'
|
57
71
|
description: This library provides arbitrary-precision decimal floating-point number
|
58
72
|
class.
|
59
73
|
email:
|