ruby-decimal 0.2.2 → 1.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 +7 -0
- data/.gitignore +28 -0
- data/Gemfile +3 -0
- data/History.txt +4 -0
- data/{README.txt → README.rdoc} +9 -0
- data/Rakefile +16 -30
- data/expand.rb +177 -0
- data/lib/decimal.rb +7 -3
- data/lib/decimal/shortcut.rb +1 -6
- data/lib/decimal/version.rb +2 -8
- data/test/helper.rb +2 -2
- data/test/test_basic.rb +1 -1
- data/test/test_coercion.rb +1 -1
- data/test/test_comparisons.rb +1 -1
- data/test/test_dectest.rb +1 -1
- data/test/test_define_conversions.rb +2 -9
- data/test/test_epsilon.rb +1 -1
- data/test/test_exact.rb +1 -2
- data/test/test_flags.rb +8 -9
- data/test/test_flt_wrapping.rb +12 -0
- data/test/test_multithreading.rb +1 -3
- data/test/test_odd_even.rb +1 -1
- data/test/test_round.rb +1 -2
- data/test/test_shortcut.rb +11 -0
- data/test/test_to_int.rb +1 -1
- data/test/test_to_rf.rb +1 -1
- data/test/test_ulp.rb +1 -1
- metadata +80 -73
- data/lib/decimal/decimal.rb +0 -4171
- data/lib/decimal/support.rb +0 -337
- data/setup.rb +0 -1585
- data/tasks/ann.rake +0 -80
- data/tasks/bones.rake +0 -20
- data/tasks/gem.rake +0 -192
- data/tasks/git.rake +0 -40
- data/tasks/manifest.rake +0 -48
- data/tasks/notes.rake +0 -27
- data/tasks/post_load.rake +0 -39
- data/tasks/rdoc.rake +0 -50
- data/tasks/rubyforge.rake +0 -55
- data/tasks/setup.rb +0 -279
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36927ec99a5725f0a164d2f65be139c6568d283d
|
4
|
+
data.tar.gz: b18eda19bb2b67f9b4368811b588d636d6434fec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f64af5058dc9622d29522ada25f980a3e57fea60cdcad2e07de71f5649aba3f676f16ee71114a98adbf3ea258da54fa781b6519b1c1b2fe01eee5b1f1d01b04c
|
7
|
+
data.tar.gz: 4d4275b7bc4910f707c49756e15129cd67ac4dd5c659613eaa58ab30e8b3a1acae04ab5c51d6c50b5661708d86e051b5425623c285673e56497c826710c3c398
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
test/dectest/*
|
2
|
+
email.txt
|
3
|
+
ruby-decimal.gemspec
|
4
|
+
html
|
5
|
+
.DS_Store
|
6
|
+
pkg
|
7
|
+
.rbx
|
8
|
+
rdoc
|
9
|
+
test/trigtest
|
10
|
+
test/tmp
|
11
|
+
*.gem
|
12
|
+
*.rbc
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.yardoc
|
16
|
+
Gemfile.lock
|
17
|
+
InstalledFiles
|
18
|
+
_yardoc
|
19
|
+
coverage
|
20
|
+
doc/
|
21
|
+
lib/bundler/man
|
22
|
+
flt/version_tmp
|
23
|
+
tmp
|
24
|
+
*.bundle
|
25
|
+
*.so
|
26
|
+
*.o
|
27
|
+
*.a
|
28
|
+
mkmf.log
|
data/Gemfile
ADDED
data/History.txt
CHANGED
data/{README.txt → README.rdoc}
RENAMED
@@ -1,3 +1,12 @@
|
|
1
|
+
= Announcement
|
2
|
+
|
3
|
+
The Ruby-Decimal package has been superseded by Flt:
|
4
|
+
* Code: http://github.com/jgoizueta/flt/
|
5
|
+
* Documentation: http://flt.rubyforge.org/
|
6
|
+
|
7
|
+
Version 1.0.0 of this gem has been redefined to use Flt and setup
|
8
|
+
an interface mostly compatible with the original Ruby-Decimal.
|
9
|
+
|
1
10
|
= Introduction
|
2
11
|
|
3
12
|
Decimal is a standards-compliant arbitrary precision decimal floating-point type for Ruby.
|
data/Rakefile
CHANGED
@@ -1,35 +1,21 @@
|
|
1
|
-
|
2
|
-
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
-
# are where the options are used.
|
1
|
+
require "bundler/gem_tasks"
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
require 'rake/testtask'
|
4
|
+
Rake::TestTask.new(:test) do |test|
|
5
|
+
test.libs << 'lib' << 'test'
|
6
|
+
test.pattern = 'test/**/test_*.rb'
|
7
|
+
test.verbose = true
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
require 'rdoc/task'
|
11
|
+
Rake::RDocTask.new do |rdoc|
|
12
|
+
version = Decimal::DECIMAL_VERSION
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
PROJ.email = 'javier@goizueta.info'
|
23
|
-
PROJ.version = DecimalSupport::VERSION::STRING
|
24
|
-
PROJ.rubyforge.name = 'ruby-decimal'
|
25
|
-
PROJ.url = "http://#{PROJ.rubyforge.name}.rubyforge.org"
|
26
|
-
PROJ.rdoc.opts = [
|
27
|
-
"--main", "README.txt",
|
28
|
-
'--title', 'Ruby Decimal Documentation',
|
29
|
-
"--opname", "index.html",
|
30
|
-
"--line-numbers",
|
31
|
-
"--inline-source"
|
32
|
-
]
|
33
|
-
#PROJ.test.file = 'test/all_tests.rb'
|
14
|
+
rdoc.rdoc_dir = 'rdoc'
|
15
|
+
rdoc.title = "Decimal #{version}"
|
16
|
+
rdoc.main = "README.rdoc"
|
17
|
+
rdoc.rdoc_files.include('README*')
|
18
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
end
|
34
20
|
|
35
|
-
|
21
|
+
task default: :test
|
data/expand.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'irb/ruby-lex'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class MimickIRB < RubyLex
|
5
|
+
attr_accessor :started
|
6
|
+
|
7
|
+
class Continue < StandardError; end
|
8
|
+
class Empty < StandardError; end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
set_input(StringIO.new)
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(str,line_no=nil)
|
16
|
+
obj = nil
|
17
|
+
@io << str
|
18
|
+
@io.rewind
|
19
|
+
unless l = lex
|
20
|
+
raise Empty if @line == ''
|
21
|
+
else
|
22
|
+
case l.strip
|
23
|
+
when "reset"
|
24
|
+
@line = ""
|
25
|
+
when "time"
|
26
|
+
@line = "puts %{You started \#{IRBalike.started.since} ago.}"
|
27
|
+
else
|
28
|
+
@line << l << "\n"
|
29
|
+
if @ltype or @continue or @indent > 0
|
30
|
+
raise Continue
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
unless @line.empty?
|
35
|
+
obj = eval @line, TOPLEVEL_BINDING
|
36
|
+
end
|
37
|
+
@line = ''
|
38
|
+
#@line_no = line_no if line_no
|
39
|
+
@exp_line_no = line_no || @line_no
|
40
|
+
|
41
|
+
@indent = 0
|
42
|
+
@indent_stack = []
|
43
|
+
|
44
|
+
$stdout.rewind
|
45
|
+
output = $stdout.read
|
46
|
+
$stdout.truncate(0)
|
47
|
+
$stdout.rewind
|
48
|
+
[output, obj]
|
49
|
+
rescue Object => e
|
50
|
+
case e when Empty, Continue
|
51
|
+
else @line = ""
|
52
|
+
end
|
53
|
+
raise e
|
54
|
+
ensure
|
55
|
+
set_input(StringIO.new)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# TO DO: output of blocks is gathered and shown at the end of the block
|
61
|
+
# when lines in a block have ->, they should be rememberd, and when
|
62
|
+
# output is generated when closing the block, each output line should
|
63
|
+
# be appended to the in-block -> lines before showing lines after the block.
|
64
|
+
|
65
|
+
|
66
|
+
class ExampleExpander
|
67
|
+
def initialize(sep=" -> ", align=52)
|
68
|
+
@sep = sep
|
69
|
+
@align = align
|
70
|
+
@irb = MimickIRB.new
|
71
|
+
@output = ""
|
72
|
+
end
|
73
|
+
def add_line(line,line_num=nil)
|
74
|
+
line = line.chomp
|
75
|
+
line = $1 if /(.+)#{@sep}.*/.match line
|
76
|
+
$stdout = StringIO.new
|
77
|
+
begin
|
78
|
+
out,obj = @irb.run(line, line_num)
|
79
|
+
@output << line_output(line,out)
|
80
|
+
rescue MimickIRB::Empty
|
81
|
+
@output << line_output(line)
|
82
|
+
rescue MimickIRB::Continue
|
83
|
+
@output << line_output(line)
|
84
|
+
rescue Object => e
|
85
|
+
#msg = "Exception : #{e.message}"
|
86
|
+
msg = "Exception : #{e.class}"
|
87
|
+
# msg = "#{e.class}: #{e.message}"
|
88
|
+
@output << line_output(line,msg)
|
89
|
+
STDERR.puts "#{msg}\n"
|
90
|
+
end
|
91
|
+
$stdout = STDOUT
|
92
|
+
end
|
93
|
+
def output
|
94
|
+
@output
|
95
|
+
end
|
96
|
+
def clear
|
97
|
+
@output = ""
|
98
|
+
end
|
99
|
+
protected
|
100
|
+
def line_output(line,output=nil)
|
101
|
+
if output
|
102
|
+
output = output.chomp
|
103
|
+
output = nil if output.strip.empty?
|
104
|
+
end
|
105
|
+
out = line.dup
|
106
|
+
if output
|
107
|
+
line_size = line.size
|
108
|
+
output.split("\n").each do |out_line|
|
109
|
+
out << " "*[0,(@align-line_size)].max + @sep + out_line
|
110
|
+
out << "\n"
|
111
|
+
line_size = 0
|
112
|
+
end
|
113
|
+
end
|
114
|
+
out
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def expand_text(txt,non_code_block_prefix=nil) # text with indented blocks of code
|
120
|
+
exex = ExampleExpander.new
|
121
|
+
indent = nil
|
122
|
+
|
123
|
+
txt_out = ""
|
124
|
+
|
125
|
+
line_num = 0
|
126
|
+
accum = ""
|
127
|
+
skip_until_blank = false
|
128
|
+
disabled = false
|
129
|
+
txt.split("\n").each do |line|
|
130
|
+
line_num += 1
|
131
|
+
code = false
|
132
|
+
line.chomp!
|
133
|
+
|
134
|
+
if skip_until_blank
|
135
|
+
if line.strip.empty?
|
136
|
+
skip_until_blank = false
|
137
|
+
end
|
138
|
+
else
|
139
|
+
|
140
|
+
unless line.strip.empty? || disabled
|
141
|
+
line_indent = /^\s*/.match(line)[0]
|
142
|
+
indent ||= line_indent
|
143
|
+
indent = line_indent if line_indent.size < indent.size
|
144
|
+
if line[line_indent.size,1]=='*'
|
145
|
+
inner_indent = /^\s*/.match(line[line_indent.size+1..-1])[0]
|
146
|
+
indent += '*'+inner_indent
|
147
|
+
else
|
148
|
+
if line_indent.size > indent.size
|
149
|
+
code = true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
if code
|
154
|
+
exex.add_line line, line_num
|
155
|
+
line = exex.output.chomp
|
156
|
+
exex.clear
|
157
|
+
else
|
158
|
+
disabled = true if line[0,7]=="EXPAND-"
|
159
|
+
disabled = false if line[0,7]=="EXPAND+"
|
160
|
+
skip_until_blank = true if line[0,1]==non_code_block_prefix
|
161
|
+
end
|
162
|
+
end
|
163
|
+
txt_out << line + "\n"
|
164
|
+
end
|
165
|
+
txt_out
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
require 'rubygems'
|
170
|
+
|
171
|
+
$:.unshift File.dirname(__FILE__) + '/lib'
|
172
|
+
|
173
|
+
|
174
|
+
require File.dirname(__FILE__) + '/lib/decimal'
|
175
|
+
|
176
|
+
|
177
|
+
puts expand_text(File.read(ARGV.shift),"[")
|
data/lib/decimal.rb
CHANGED
data/lib/decimal/shortcut.rb
CHANGED
data/lib/decimal/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
|
2
|
+
$: << "." unless $:.include?(".") # for Ruby 1.9.2
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'/../lib/decimal'))
|
3
4
|
|
4
5
|
def initialize_context
|
5
6
|
Decimal.context = Decimal::ExtendedContext
|
6
7
|
end
|
7
|
-
|
data/test/test_basic.rb
CHANGED
data/test/test_coercion.rb
CHANGED
data/test/test_comparisons.rb
CHANGED
data/test/test_dectest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
2
2
|
|
3
3
|
class TestDefineConversions < Test::Unit::TestCase
|
4
4
|
|
@@ -55,14 +55,7 @@ class TestDefineConversions < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
assert_raise(TypeError) { Decimal('0') == BigDecimal.new('0') }
|
59
|
-
assert_not_equal BigDecimal.new('0'), Decimal('0')
|
60
|
-
assert_not_equal BigDecimal.new('1.2345'), Decimal('1.2345')
|
61
|
-
assert_not_equal BigDecimal.new('-1.2345'), Decimal('-1.2345')
|
62
|
-
assert_not_equal BigDecimal.new('1.2345'), Decimal('0.0012345000E3')
|
63
|
-
assert_raise(TypeError) { BigDecimal.new('7')+Decimal('0.1') }
|
64
|
-
assert_raise(TypeError) { Decimal('7')+BigDecimal.new('0.1') }
|
65
|
-
assert_raise(TypeError) { Decimal(BigDecimal.new('1.1')) }
|
58
|
+
assert_raise(TypeError, RuntimeError) { Decimal('0') == BigDecimal.new('0') }
|
66
59
|
|
67
60
|
['0.1', '-0.1', '0.0', '1234567.1234567', '-1234567.1234567', '1.234E7', '1.234E-7'].each do |n|
|
68
61
|
assert_raise(TypeError) { Decimal(n).convert_to(BigDecimal) }
|
data/test/test_epsilon.rb
CHANGED
data/test/test_exact.rb
CHANGED
data/test/test_flags.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
|
3
2
|
|
4
3
|
class TestFlags < Test::Unit::TestCase
|
5
4
|
|
@@ -7,21 +6,21 @@ class TestFlags < Test::Unit::TestCase
|
|
7
6
|
f = DecimalSupport::Flags(:flag_one, :flag_three)
|
8
7
|
assert_equal "[:flag_one, :flag_three]", f.to_a.sort_by{|flg| flg.to_s}.inspect
|
9
8
|
f.values = DecimalSupport::FlagValues(:flag_one, :flag_two, :flag_three)
|
10
|
-
|
9
|
+
assert_match /::Flags\[flag_one, flag_three\] \(0x5\)$/, f.inspect
|
11
10
|
f[:flag_two] = true
|
12
|
-
|
11
|
+
assert_match /::Flags\[flag_one, flag_two, flag_three\] \(0x7\)$/, f.inspect
|
13
12
|
f[:flag_one] = false
|
14
|
-
|
13
|
+
assert_match /::Flags\[flag_two, flag_three\] \(0x6\)$/, f.inspect
|
15
14
|
f.clear!
|
16
|
-
|
15
|
+
assert_match /::Flags\[\] \(0x0\)$/, f.inspect
|
17
16
|
f << [:flag_one,:flag_two]
|
18
|
-
|
17
|
+
assert_match /::Flags\[flag_one, flag_two\] \(0x3\)$/, f.inspect
|
19
18
|
g = DecimalSupport::Flags(f.values)
|
20
19
|
g.bits = f.bits
|
21
|
-
|
20
|
+
assert_match /::Flags\[flag_one, flag_two\] \(0x3\)$/, g.inspect
|
22
21
|
assert g==f
|
23
22
|
g.set!
|
24
|
-
|
23
|
+
assert_match /::Flags\[flag_one, flag_two, flag_three\] \(0x7\)$/, g.inspect
|
25
24
|
assert g!=f
|
26
25
|
|
27
26
|
assert DecimalSupport::Flags(:flag_one, :flag_three)==DecimalSupport::Flags(:flag_three, :flag_one)
|