ruby-decimal 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -29,3 +29,7 @@
29
29
  - After a local context, the global context was set to a copy of the original
30
30
  context, so any previously stored reference to it was now unbound.
31
31
  - Context#normalize was incorrect.
32
+
33
+ == 1.0.0 2014-10-12
34
+
35
+ * Reimplemented based on Flt
@@ -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
- # Look in the tasks/setup.rb file for the various options that can be
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
- begin
6
- require 'bones'
7
- Bones.setup
8
- rescue LoadError
9
- load 'tasks/setup.rb'
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
- ensure_in_path 'lib'
13
- #require 'decimal'
14
- require 'decimal/version'
10
+ require 'rdoc/task'
11
+ Rake::RDocTask.new do |rdoc|
12
+ version = Decimal::DECIMAL_VERSION
15
13
 
16
- task :default => 'spec:run'
17
-
18
-
19
- PROJ.name = 'ruby-decimal'
20
- PROJ.description = "Ruby Decimal Type"
21
- PROJ.authors = 'Javier Goizueta'
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
- # EOF
21
+ task default: :test
@@ -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),"[")
@@ -1,4 +1,8 @@
1
- $:.unshift File.dirname(__FILE__)
1
+ require 'flt/dec_num'
2
2
 
3
- require 'decimal/support'
4
- require 'decimal/decimal'
3
+ Decimal = Flt::DecNum
4
+ DecimalSupport = Flt::Support
5
+
6
+ def Decimal(*args)
7
+ Flt::DecNum[*args]
8
+ end
@@ -1,6 +1 @@
1
- require 'decimal'
2
-
3
- D = Decimal
4
- def D(*args)
5
- Decimal(*args)
6
- end
1
+ require 'flt/d'
@@ -1,9 +1,3 @@
1
- module DecimalSupport
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 2
5
- TINY = 2
1
+ require 'decimal'
6
2
 
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end
3
+ Decimal::DECIMAL_VERSION = "1.0.0"
@@ -1,7 +1,7 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/decimal'
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
-
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
  def exp(x,c=nil)
4
4
  i, lasts, s, fact, num = 0, 0, 1, 1, 1
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
  class TestCoercion < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
  class TestComparisons < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
  ROUNDINGS = {
4
4
  'ceiling' => :ceiling,
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
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) }
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
2
 
3
3
  class TestEpsilon < Test::Unit::TestCase
4
4
 
@@ -1,5 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
2
-
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
3
2
 
4
3
  class TestExact < Test::Unit::TestCase
5
4
 
@@ -1,5 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper.rb'
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
- assert_equal "DecimalSupport::Flags[flag_one, flag_three] (0x5)", f.inspect
9
+ assert_match /::Flags\[flag_one, flag_three\] \(0x5\)$/, f.inspect
11
10
  f[:flag_two] = true
12
- assert_equal "DecimalSupport::Flags[flag_one, flag_two, flag_three] (0x7)", f.inspect
11
+ assert_match /::Flags\[flag_one, flag_two, flag_three\] \(0x7\)$/, f.inspect
13
12
  f[:flag_one] = false
14
- assert_equal "DecimalSupport::Flags[flag_two, flag_three] (0x6)", f.inspect
13
+ assert_match /::Flags\[flag_two, flag_three\] \(0x6\)$/, f.inspect
15
14
  f.clear!
16
- assert_equal "DecimalSupport::Flags[] (0x0)", f.inspect
15
+ assert_match /::Flags\[\] \(0x0\)$/, f.inspect
17
16
  f << [:flag_one,:flag_two]
18
- assert_equal "DecimalSupport::Flags[flag_one, flag_two] (0x3)", f.inspect
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
- assert_equal "DecimalSupport::Flags[flag_one, flag_two] (0x3)", g.inspect
20
+ assert_match /::Flags\[flag_one, flag_two\] \(0x3\)$/, g.inspect
22
21
  assert g==f
23
22
  g.set!
24
- assert_equal "DecimalSupport::Flags[flag_one, flag_two, flag_three] (0x7)", g.inspect
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)
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
+
3
+ class TestFltWrapping < Test::Unit::TestCase
4
+
5
+ def test_flt_wrapping
6
+ assert_equal Flt::DecNum, Decimal
7
+
8
+ assert_equal Flt::DecNum('0.1'), Decimal('0.1')
9
+ end
10
+
11
+ end
12
+