nio 0.2.1 → 0.2.2

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.
@@ -1,44 +1,44 @@
1
- # Common Utilities
2
-
3
- # Copyright (C) 2003-2005, Javier Goizueta <javier@goizueta.info>
4
- #
5
- # This program is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU General Public License
7
- # as published by the Free Software Foundation; either version 2
8
- # of the License, or (at your option) any later version.
9
-
10
-
11
- require 'rubygems'
12
-
13
-
14
-
15
- module Nio
16
-
17
- module StateEquivalent
18
- def ==(obj); test_equal(obj); end
19
- def eql?(obj); test_equal(obj); end
20
- def ===(obj); test_equal(obj); end
21
- def hash
22
- h = 0
23
- self.instance_variables.each do |var|
24
- v = self.instance_eval var
25
- h ^= v.hash unless v.nil?
26
- end
27
- h
28
- end
29
-
30
- private
31
- def test_equal(obj)
32
- return false unless self.class == obj.class
33
- (self.instance_variables + obj.instance_variables).uniq.each do |var|
34
- v1 = self.instance_eval var
35
- v2 = obj.instance_eval var
36
- return false unless v1 == v2
37
- end
38
- true
39
- end
40
- end
41
-
42
- module_function
43
-
44
- end
1
+ # Common Utilities
2
+
3
+ # Copyright (C) 2003-2005, Javier Goizueta <javier@goizueta.info>
4
+ #
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License
7
+ # as published by the Free Software Foundation; either version 2
8
+ # of the License, or (at your option) any later version.
9
+
10
+
11
+ require 'rubygems'
12
+
13
+
14
+
15
+ module Nio
16
+
17
+ module StateEquivalent
18
+ def ==(obj); test_equal(obj); end
19
+ def eql?(obj); test_equal(obj); end
20
+ def ===(obj); test_equal(obj); end
21
+ def hash
22
+ h = 0
23
+ self.instance_variables.each do |var|
24
+ v = self.instance_eval var.to_s
25
+ h ^= v.hash unless v.nil?
26
+ end
27
+ h
28
+ end
29
+
30
+ private
31
+ def test_equal(obj)
32
+ return false unless self.class == obj.class
33
+ (self.instance_variables + obj.instance_variables).uniq.each do |var|
34
+ v1 = self.instance_eval var.to_s
35
+ v2 = obj.instance_eval var.to_s
36
+ return false unless v1 == v2
37
+ end
38
+ true
39
+ end
40
+ end
41
+
42
+ module_function
43
+
44
+ end
@@ -2,7 +2,7 @@ module Nio #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,69 +1,69 @@
1
- # nuweb build tasks
2
-
3
- desc "Generate Ruby code"
4
- task :tangle => Dir['source/*.w'].collect{|fn| fn.gsub /\.w/,'.ws'}+Dir['source/lib/**/*.rb'].collect{|fn| fn.gsub('source/lib/','lib/')}+[:test]
5
-
6
- # directory 'lib'
7
- # directory 'lib/nio'
8
- # directory 'source/pdf'
9
-
10
- rule '.ws' => ['.w'] do |t|
11
- puts "build dir: #{Dir.pwd}"
12
- puts "nuweb -t #{t.source}"
13
- puts `nuweb -t #{t.source}`
14
- File.open(t.name,'w'){|f| f.puts "sentinel"}
15
- end
16
-
17
- clean_exts = ['*.tex','*.dvi','*.log','*.aux','*.out','*.ws']
18
-
19
- desc "clean up files"
20
- task :clean_nuweb do |t| # to do: integrate in hoe clean
21
- rm_r clean_exts.collect{|x| Dir.glob('*'+x)+Dir.glob('source/*'+x)+Dir.glob('source/pdf/*'+x)}.flatten
22
- end
23
-
24
- desc "Generate source code (nuweb) documentation"
25
- task :weave => ['source/pdf'] + Dir['source/*.w'].collect{|fn| fn.gsub(/\.w/,'.pdf').gsub('source/','source/pdf/')}
26
-
27
- def rem_ext(fn, ext)
28
- ext = File.extname(fn) unless fn
29
- File.join(File.dirname(fn),File.basename(fn,ext))
30
- end
31
-
32
- def sub_dir(dir, fn)
33
- d,n = File.split(fn)
34
- File.join(d,File.join(dir,n))
35
- end
36
-
37
- def rep_dir(dir, fn)
38
- File.join(dir, File.basename(fn))
39
- end
40
-
41
- #note that if latex is run from the base directory and the file is in a subdirectory (source)
42
- # .aux/.out/.log files are created in the subdirectory and won't be found by the second
43
- # pass of latex;
44
- def w_to_pdf(s)
45
- fn = rem_ext(s,'.w')
46
- puts "dir: #{File.dirname(fn)}"
47
- doc_dir = File.dirname(fn)!='.' ? './pdf' : '../source/pdf'
48
- cd(File.dirname(fn)) do
49
- fn = File.basename(fn)
50
- 2.times do
51
- puts "nuweb -o -l #{fn}.w"
52
- puts `nuweb -o -l #{fn}.w`
53
- puts "latex -halt-on-error #{fn}.tex"
54
- puts `latex -halt-on-error #{fn}.tex`
55
- puts "dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi"
56
- puts `dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi`
57
- end
58
- end
59
- end
60
-
61
- rule '.pdf' => [proc{|tn| File.join('source',File.basename(tn,'.pdf')+'.w')}] do |t|
62
- w_to_pdf t.source
63
- end
64
-
65
- rule /\Alib\/.*\.rb/ =>[proc{|tn| tn.sub(/\Alib\//, 'source/lib/') }] do |t|
66
- cp t.source, t.name if t.source
67
- end
68
-
69
-
1
+ # nuweb build tasks
2
+
3
+ desc "Generate Ruby code"
4
+ task :tangle => Dir['source/*.w'].collect{|fn| fn.gsub /\.w/,'.ws'}+Dir['source/lib/**/*.rb'].collect{|fn| fn.gsub('source/lib/','lib/')}+[:test]
5
+
6
+ # directory 'lib'
7
+ # directory 'lib/nio'
8
+ # directory 'source/pdf'
9
+
10
+ rule '.ws' => ['.w'] do |t|
11
+ puts "build dir: #{Dir.pwd}"
12
+ puts "nuweb -t #{t.source}"
13
+ puts `nuweb -t #{t.source}`
14
+ File.open(t.name,'w'){|f| f.puts "sentinel"}
15
+ end
16
+
17
+ clean_exts = ['*.tex','*.dvi','*.log','*.aux','*.out','*.ws']
18
+
19
+ desc "clean up files"
20
+ task :clean_nuweb do |t| # to do: integrate in hoe clean
21
+ rm_r clean_exts.collect{|x| Dir.glob('*'+x)+Dir.glob('source/*'+x)+Dir.glob('source/pdf/*'+x)}.flatten
22
+ end
23
+
24
+ desc "Generate source code (nuweb) documentation"
25
+ task :weave => ['source/pdf'] + Dir['source/*.w'].collect{|fn| fn.gsub(/\.w/,'.pdf').gsub('source/','source/pdf/')}
26
+
27
+ def rem_ext(fn, ext)
28
+ ext = File.extname(fn) unless fn
29
+ File.join(File.dirname(fn),File.basename(fn,ext))
30
+ end
31
+
32
+ def sub_dir(dir, fn)
33
+ d,n = File.split(fn)
34
+ File.join(d,File.join(dir,n))
35
+ end
36
+
37
+ def rep_dir(dir, fn)
38
+ File.join(dir, File.basename(fn))
39
+ end
40
+
41
+ #note that if latex is run from the base directory and the file is in a subdirectory (source)
42
+ # .aux/.out/.log files are created in the subdirectory and won't be found by the second
43
+ # pass of latex;
44
+ def w_to_pdf(s)
45
+ fn = rem_ext(s,'.w')
46
+ puts "dir: #{File.dirname(fn)}"
47
+ doc_dir = File.dirname(fn)!='.' ? './pdf' : '../source/pdf'
48
+ cd(File.dirname(fn)) do
49
+ fn = File.basename(fn)
50
+ 2.times do
51
+ puts "nuweb -o -l #{fn}.w"
52
+ puts `nuweb -o -l #{fn}.w`
53
+ puts "latex -halt-on-error #{fn}.tex"
54
+ puts `latex -halt-on-error #{fn}.tex`
55
+ puts "dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi"
56
+ puts `dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi`
57
+ end
58
+ end
59
+ end
60
+
61
+ rule '.pdf' => [proc{|tn| File.join('source',File.basename(tn,'.pdf')+'.w')}] do |t|
62
+ w_to_pdf t.source
63
+ end
64
+
65
+ rule /\Alib\/.*\.rb/ =>[proc{|tn| tn.sub(/\Alib\//, 'source/lib/') }] do |t|
66
+ cp t.source, t.name if t.source
67
+ end
68
+
69
+
@@ -1,101 +1,101 @@
1
- ---
2
- - A91C2BB757F72141
3
- - D84014519CD8253F
4
- - BF30A46FFF51ED3F
5
- - 91D03B54623CC03E
6
- - D403F243699B4B3F
7
- - 6D1F99449A26D540
8
- - 92817CDBC7715E3F
9
- - 72696E8F13BB323F
10
- - 683C16C10F79FE3E
11
- - 22801BA12A074740
12
- - 7081D3172A53E5BF
13
- - C0DE790FC0FBE9BF
14
- - 3AE5F0923E55D33F
15
- - 92B6BEEC140A8FBF
16
- - CE66ABACDBD80F3F
17
- - ACC70B95DCFF6BC0
18
- - 1461EF81707378BF
19
- - AE09EC08D0F1ADBF
20
- - 34DA3FFF72E9D83F
21
- - C664AD3F9AC4BFBF
22
- - 2101BE78DFDC74BE
23
- - 7EE9B042D4628140
24
- - 90368189CC8D753F
25
- - 337C9D874DC4C5BE
26
- - 0CFDA79A7FDCED3F
27
- - EC94C739F2CFB3BF
28
- - 1D5436848A1AEBBE
29
- - B725B6C420034640
30
- - 48C692FEAA59DEBF
31
- - BC4CB816B0BAB5BF
32
- - C2D835BC80B99A40
33
- - 6A565C2E720847BF
34
- - 050189AF84C84EC1
35
- - 0060B28B63B5DC3F
36
- - 18A387F2A64E5FC0
37
- - FBC8B0D428E302C1
38
- - A30DD43ED762B4C0
39
- - 3D85522EC70AFDBE
40
- - FCF62D2923F0583F
41
- - DB588C2A9C26FBC0
42
- - BA4E1863DBE6FCBE
43
- - 5C34946E1A12D33F
44
- - 90E63D7E81888740
45
- - 82541C0DE9F1443F
46
- - 9F2A7781EE4B683F
47
- - 0082C4B6393EA7BF
48
- - 768EDD6B97D19540
49
- - 87BA76258BEBFBBE
50
- - 7A6580A6639DD7BF
51
- - 26DDD435F13B12BF
52
- - 1AF857C69682DBBF
53
- - E731C0DCDAAE51BF
54
- - DB9DB0551A511F3F
55
- - 04977B9C4C73D13F
56
- - 44D5BB96C84587C0
57
- - CE3DE8C2DF9942BF
58
- - 23F12DE055F30C3F
59
- - C10951998E1B7440
60
- - 1CC3F51802F309C0
61
- - FB97E7DB6B081DC1
62
- - 5C811354280FEA3F
63
- - A405ED0A749718BF
64
- - 322939F71F7A51BF
65
- - F3E06C6EEB2342BF
66
- - 5A6D9DF3F879D3C0
67
- - BC466E35C5AF9940
68
- - EB4571E54EB7CD3F
69
- - BBA9A8401CD4D13F
70
- - 6A565DEA5E4F8A40
71
- - 20586794310B93BF
72
- - 80B8449C203B9BC0
73
- - 0E9C461358F4AABF
74
- - 469E0A1D42DEA73F
75
- - 711DA636DD2C41BF
76
- - 414A9E166BE2A0C0
77
- - 407FF9F39253F2BE
78
- - BAD158256942D4C0
79
- - 2D4424FE12BE94BF
80
- - 7F0F15B537E997C0
81
- - 4ADF1BD93C66F1BF
82
- - 2DAF002ADBC1E0BF
83
- - 3739FF3C2BE601C0
84
- - 38ACCEAE7B88083F
85
- - 7C2D9D7FA150C23F
86
- - B726087920E8EA3F
87
- - C075B44F459250BE
88
- - 9EDAB9C61F7D783F
89
- - 2FE6362CACE5153F
90
- - 98A24B93A2F4C33E
91
- - 6FD39CEB5C7F15C0
92
- - C5BE550840E4503F
93
- - 214EA7E4F9619640
94
- - 4DEF9253DE1C10C0
95
- - B8C76C5B85E4FDBF
96
- - 07D21EB7A400F13F
97
- - DB103669202EAEBF
98
- - 9F59E7B3EA71E63F
99
- - 83712959474BF440
100
- - 8D5B7FA245A650BF
101
- - 16FAF25CCBB8ECBE
1
+ ---
2
+ - A91C2BB757F72141
3
+ - D84014519CD8253F
4
+ - BF30A46FFF51ED3F
5
+ - 91D03B54623CC03E
6
+ - D403F243699B4B3F
7
+ - 6D1F99449A26D540
8
+ - 92817CDBC7715E3F
9
+ - 72696E8F13BB323F
10
+ - 683C16C10F79FE3E
11
+ - 22801BA12A074740
12
+ - 7081D3172A53E5BF
13
+ - C0DE790FC0FBE9BF
14
+ - 3AE5F0923E55D33F
15
+ - 92B6BEEC140A8FBF
16
+ - CE66ABACDBD80F3F
17
+ - ACC70B95DCFF6BC0
18
+ - 1461EF81707378BF
19
+ - AE09EC08D0F1ADBF
20
+ - 34DA3FFF72E9D83F
21
+ - C664AD3F9AC4BFBF
22
+ - 2101BE78DFDC74BE
23
+ - 7EE9B042D4628140
24
+ - 90368189CC8D753F
25
+ - 337C9D874DC4C5BE
26
+ - 0CFDA79A7FDCED3F
27
+ - EC94C739F2CFB3BF
28
+ - 1D5436848A1AEBBE
29
+ - B725B6C420034640
30
+ - 48C692FEAA59DEBF
31
+ - BC4CB816B0BAB5BF
32
+ - C2D835BC80B99A40
33
+ - 6A565C2E720847BF
34
+ - 050189AF84C84EC1
35
+ - 0060B28B63B5DC3F
36
+ - 18A387F2A64E5FC0
37
+ - FBC8B0D428E302C1
38
+ - A30DD43ED762B4C0
39
+ - 3D85522EC70AFDBE
40
+ - FCF62D2923F0583F
41
+ - DB588C2A9C26FBC0
42
+ - BA4E1863DBE6FCBE
43
+ - 5C34946E1A12D33F
44
+ - 90E63D7E81888740
45
+ - 82541C0DE9F1443F
46
+ - 9F2A7781EE4B683F
47
+ - 0082C4B6393EA7BF
48
+ - 768EDD6B97D19540
49
+ - 87BA76258BEBFBBE
50
+ - 7A6580A6639DD7BF
51
+ - 26DDD435F13B12BF
52
+ - 1AF857C69682DBBF
53
+ - E731C0DCDAAE51BF
54
+ - DB9DB0551A511F3F
55
+ - 04977B9C4C73D13F
56
+ - 44D5BB96C84587C0
57
+ - CE3DE8C2DF9942BF
58
+ - 23F12DE055F30C3F
59
+ - C10951998E1B7440
60
+ - 1CC3F51802F309C0
61
+ - FB97E7DB6B081DC1
62
+ - 5C811354280FEA3F
63
+ - A405ED0A749718BF
64
+ - 322939F71F7A51BF
65
+ - F3E06C6EEB2342BF
66
+ - 5A6D9DF3F879D3C0
67
+ - BC466E35C5AF9940
68
+ - EB4571E54EB7CD3F
69
+ - BBA9A8401CD4D13F
70
+ - 6A565DEA5E4F8A40
71
+ - 20586794310B93BF
72
+ - 80B8449C203B9BC0
73
+ - 0E9C461358F4AABF
74
+ - 469E0A1D42DEA73F
75
+ - 711DA636DD2C41BF
76
+ - 414A9E166BE2A0C0
77
+ - 407FF9F39253F2BE
78
+ - BAD158256942D4C0
79
+ - 2D4424FE12BE94BF
80
+ - 7F0F15B537E997C0
81
+ - 4ADF1BD93C66F1BF
82
+ - 2DAF002ADBC1E0BF
83
+ - 3739FF3C2BE601C0
84
+ - 38ACCEAE7B88083F
85
+ - 7C2D9D7FA150C23F
86
+ - B726087920E8EA3F
87
+ - C075B44F459250BE
88
+ - 9EDAB9C61F7D783F
89
+ - 2FE6362CACE5153F
90
+ - 98A24B93A2F4C33E
91
+ - 6FD39CEB5C7F15C0
92
+ - C5BE550840E4503F
93
+ - 214EA7E4F9619640
94
+ - 4DEF9253DE1C10C0
95
+ - B8C76C5B85E4FDBF
96
+ - 07D21EB7A400F13F
97
+ - DB103669202EAEBF
98
+ - 9F59E7B3EA71E63F
99
+ - 83712959474BF440
100
+ - 8D5B7FA245A650BF
101
+ - 16FAF25CCBB8ECBE
@@ -1,376 +1,410 @@
1
-
2
-
3
- # Copyright (C) 2003-2005, Javier Goizueta <javier@goizueta.info>
4
- #
5
- # This program is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU General Public License
7
- # as published by the Free Software Foundation; either version 2
8
- # of the License, or (at your option) any later version.
9
-
10
- #require File.dirname(__FILE__) + '/test_helper.rb'
11
- require 'test/unit'
12
- require 'nio/rtnlzr'
13
- require 'nio/repdec'
14
- require 'nio/fmt'
15
- include Nio
16
- require 'yaml'
17
-
18
- def neighbours(x)
19
- f,e = Math.frexp(x)
20
- e = Float::MIN_EXP if f==0
21
- e = [Float::MIN_EXP,e].max
22
- dx = Math.ldexp(1,e-Float::MANT_DIG) #Math.ldexp(Math.ldexp(1.0,-Float::MANT_DIG),e)
23
- high = x + dx
24
- if e==Float::MIN_EXP || f!=0.5 #0.5==Math.ldexp(2**(bits-1),-Float::MANT_DIG)
25
- low = x - dx
26
- else
27
- low = x - dx/2 # x - Math.ldexp(Math.ldexp(1.0,-Float::MANT_DIG),e-1)
28
- end
29
- [low, high]
30
- end
31
-
32
- def prv(x)
33
- neighbours(x)[0]
34
- end
35
- def nxt(x)
36
- neighbours(x)[1]
37
- end
38
- MIN_N = Math.ldexp(0.5,Float::MIN_EXP) # == nxt(MAX_D) == Float::MIN
39
- MAX_D = Math.ldexp(Math.ldexp(1,Float::MANT_DIG-1)-1,Float::MIN_EXP-Float::MANT_DIG)
40
- MIN_D = Math.ldexp(1,Float::MIN_EXP-Float::MANT_DIG);
41
-
42
- class TestFmt < Test::Unit::TestCase
43
-
44
- def setup
45
-
46
- $data = YAML.load(File.read(File.join(File.dirname(__FILE__) ,'data.yaml'))).collect{|x| [x].pack('H*').unpack('E')[0]}
47
- $data << MIN_N
48
- $data << MAX_D
49
- $data << MIN_D
50
-
51
- end
52
-
53
- def teardown
54
-
55
- Fmt.default = Fmt.new
56
-
57
- end
58
-
59
-
60
- def test_basic_fmt
61
- # test correct rounding: 1.448997445238699 -> 6525704354437805*2^-52
62
- assert_equal Rational(6525704354437805,4503599627370496), Float.nio_read('1.448997445238699').nio_xr
63
-
64
- assert_equal "0",0.0.nio_write
65
- assert_equal "0",0.nio_write
66
- assert_equal "0",BigDecimal('0').nio_write
67
- assert_equal "0",Rational(0,1).nio_write
68
-
69
- assert_equal "123456789",123456789.0.nio_write
70
- assert_equal "123456789",123456789.nio_write
71
- assert_equal "123456789",BigDecimal('123456789').nio_write
72
- assert_equal "123456789",Rational(123456789,1).nio_write
73
- assert_equal "123456789.25",123456789.25.nio_write
74
- assert_equal "123456789.25",BigDecimal('123456789.25').nio_write
75
- assert_equal "123456789.25",(Rational(123456789)+Rational(1,4)).nio_write
76
- end
77
-
78
- def test_basic_fmt_float
79
-
80
- assert_equal 2,Float::RADIX
81
- assert_equal 53,Float::MANT_DIG
82
-
83
- fmt = Fmt.new {|f|
84
- f.rep! '[','','...',0,true
85
- f.width! 20,:right,'*'
86
- }
87
- fmt.sep! '.',',',[3]
88
-
89
- assert_equal "0.1",0.1.nio_write
90
- assert_equal "0.10000000000000001",0.1.nio_write(Fmt.mode(:gen,:exact).show_all_digits)
91
- assert_equal "0.10000000000000001",0.1.nio_write(Fmt.mode(:gen,:exact).show_all_digits(true))
92
- assert_equal "0.10000000000000001",0.1.nio_write(Fmt.mode(:gen,:exact,:show_all_digits=>true))
93
- assert_equal "0.1000000000000000055511151231257827021181583404541015625",0.1.nio_write(Fmt.mode(:gen,:exact,:approx=>:exact))
94
-
95
-
96
- assert_equal "******643,454,333.32",fmt.nio_write_formatted(fmt.nio_read_formatted("643,454,333.32"))
97
- assert_equal "******643.454.333,32",fmt.sep(',').nio_write_formatted(fmt.nio_read_formatted("643,454,333.32"))
98
- fmt.pad0s! 10
99
- num = fmt.nio_read_formatted("0.3333...")
100
- assert_equal "0000000.[3",fmt.nio_write_formatted(num)
101
- fmt.mode! :fix, 3
102
- assert_equal "000000.333",fmt.nio_write_formatted(num)
103
- num = fmt.nio_read_formatted("-0.666...")
104
- fmt.prec! :exact
105
- fmt.sep! ',','.'
106
- assert_equal "-000000,[6",fmt.nio_write_formatted(num)
107
- fmt.width! 20,:center,'*'
108
- fmt.mode! :fix,3
109
- assert_equal "*******-0,667*******",fmt.nio_write_formatted(num)
110
- num = fmt.nio_read_formatted("0,5555")
111
- fmt.prec! :exact
112
- assert_equal "*******0,5555*******",fmt.nio_write_formatted(num)
113
-
114
- Fmt.default = Fmt[:comma_th]
115
- x = Float.nio_read("11123,2343")
116
- assert_equal 11123.2343,x
117
- assert_equal "11.123,2343", x.nio_write
118
- assert_equal "11123,2343", x.nio_write(Fmt[:comma])
119
-
120
- x = Float.nio_read("-1234,5678901234e-33")
121
- # assert_equal -1.2345678901234e-030, x
122
- assert_equal "-1,2345678901234E-30", x.nio_write()
123
- assert_equal "-0,0000000000000000000000000000012346",x.nio_write(Fmt[:comma].mode(:sig,5))
124
-
125
- assert_equal "0,333...",
126
- (1.0/3).nio_write(Fmt.prec(:exact).show_all_digits(true).approx_mode(:simplify))
127
-
128
- fmt = Fmt.default
129
- assert_raises TypeError do fmt.prec! 4 end
130
- fmt = Fmt.default {|f| f.prec! 4 }
131
- assert_equal "1,235", 1.23456.nio_write(fmt)
132
- assert_equal "1,23456", 1.23456.nio_write()
133
-
134
- Fmt.default = Fmt.new
135
- assert_equal '11123.2343', 11123.2343.nio_write
136
- end
137
-
138
- def test_tol_fmt_float
139
- tol = Tolerance.new.decimals(12,:sig)
140
- fmt = Fmt.prec(12,:sig)
141
- $data.each do |x|
142
- assert tol.equals?(x, Float.nio_read(x.nio_write(fmt),fmt)), "out of tolerance: #{x.inspect} #{Float.nio_read(x.nio_write(fmt),fmt)}"
143
- assert tol.equals?(-x, Float.nio_read((-x).nio_write(fmt),fmt)), "out of tolerance: #{(-x).inspect} #{Float.nio_read((-x).nio_write(fmt),fmt)}"
144
- end
145
- end
146
-
147
- def test_BigDec
148
- assert_equal "0",BigDec(0).nio_write
149
- fmt = Fmt.mode(:gen,:exact)
150
- assert_equal "0",BigDec(0).nio_write(fmt)
151
- $data.each do |x|
152
- x = BigDecimal(x.to_s)
153
- assert_equal x,BigDecimal.nio_read(x.nio_write(fmt),fmt)
154
- end
155
- assert_equal "1E500",BigDec('1E500').nio_write
156
- assert_equal "1E-500",BigDec('1E-500').nio_write
157
- assert_equal "-1E500",BigDec('-1E500').nio_write
158
- assert_equal "-1E-500",BigDec('-1E-500').nio_write
159
- end
160
-
161
- def test_Rational
162
- assert_equal "0",Rational(0,1).nio_write
163
- fmt = Fmt.mode(:gen,:exact)
164
- assert_equal "0",Rational(0,1).nio_write(fmt)
165
- $data.each do |x|
166
- x = x.nio_xr # nio_r
167
- assert_equal x,Rational.nio_read(x.nio_write(fmt),fmt)
168
- end
169
- end
170
-
171
- def test_float_bases
172
- nfmt2 = Fmt[:comma].base(2).prec(:exact)
173
- nfmt8 = Fmt[:comma].base(8).prec(:exact)
174
- nfmt10 = Fmt[:comma].base(10).prec(:exact)
175
- nfmt16 = Fmt[:comma].base(16).prec(:exact)
176
- $data.each do |x|
177
- assert_equal(x,Float.nio_read(x.nio_write(nfmt2),nfmt2))
178
- assert_equal(x,Float.nio_read(x.nio_write(nfmt8),nfmt8))
179
- assert_equal(x,Float.nio_read(x.nio_write(nfmt10),nfmt10))
180
- assert_equal(x,Float.nio_read(x.nio_write(nfmt16),nfmt16))
181
- assert_equal(-x,Float.nio_read((-x).nio_write(nfmt2),nfmt2))
182
- assert_equal(-x,Float.nio_read((-x).nio_write(nfmt8),nfmt8))
183
- assert_equal(-x,Float.nio_read((-x).nio_write(nfmt10),nfmt10))
184
- assert_equal(-x,Float.nio_read((-x).nio_write(nfmt16),nfmt16))
185
- end
186
- end
187
-
188
- def rational_bases
189
- assert_equal "0.0001100110011...", (Rational(1)/10).nio_write(Fmt.new.base(2))
190
- end
191
-
192
- def test_big_decimal_bases
193
-
194
- assert_equal "0.1999A",(BigDec(1)/10).nio_write(Fmt.new.base(16).prec(5))
195
- assert_equal "0.1999...",(BigDec(1)/10).nio_write(Fmt.mode(:gen,:exact,:round=>:inf,:approx=>:simplify).base(16))
196
-
197
- nfmt2 = Fmt[:comma].base(2).prec(:exact)
198
- nfmt8 = Fmt[:comma].base(8).prec(:exact)
199
- nfmt10 = Fmt[:comma].base(10).prec(:exact)
200
- nfmt16 = Fmt[:comma].base(16).prec(:exact)
201
- $data.each do |x|
202
- x = BigDec(x.to_s)
203
- xs,xdig,xb,xe = x.split
204
- ndig = xdig.size
205
- round_dig = ndig-xe
206
- # note that BigDecimal.nio_read produces a BigDecimal with the exact value of the text representation
207
- # since the representation here is only aproximate (because of the base difference), we must
208
- # round the results to the precision of the original number
209
- assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt2),nfmt2).round(round_dig))
210
- assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt8),nfmt8).round(round_dig))
211
- assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt10),nfmt10).round(round_dig))
212
- assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt16),nfmt16).round(round_dig))
213
- assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt2),nfmt2).round(round_dig))
214
- assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt8),nfmt8).round(round_dig))
215
- assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt10),nfmt10).round(round_dig))
216
- assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt16),nfmt16).round(round_dig))
217
- end
218
- end
219
-
220
- def test_exact_all_float
221
- #fmt = Fmt.prec(:exact).show_all_digits(true).approx_mode(:exact)
222
- fmt = Fmt.mode(:gen,:exact,:round=>:inf,:approx=>:exact)
223
- assert_equal "0.1000000000000000055511151231257827021181583404541015625",Float.nio_read('0.1',fmt).nio_write(fmt)
224
- assert_equal "64.099999999999994315658113919198513031005859375",Float.nio_read('64.1',fmt).nio_write(fmt)
225
- assert_equal '0.5',Float.nio_read('0.5',fmt).nio_write(fmt)
226
- assert_equal "0.333333333333333314829616256247390992939472198486328125", (1.0/3.0).nio_write(fmt)
227
- assert_equal "0.66666666666666662965923251249478198587894439697265625", (2.0/3.0).nio_write(fmt)
228
- assert_equal "-0.333333333333333314829616256247390992939472198486328125", (-1.0/3.0).nio_write(fmt)
229
- assert_equal "-0.66666666666666662965923251249478198587894439697265625", (-2.0/3.0).nio_write(fmt)
230
- assert_equal "1267650600228229401496703205376", (2.0**100).nio_write(fmt)
231
- assert_equal "0.10000000000000001942890293094023945741355419158935546875", nxt(0.1).nio_write(fmt)
232
- assert_equal "1023.9999999999998863131622783839702606201171875", prv(1024).nio_write(fmt)
233
-
234
- assert_equal "2.225073858507201383090232717332404064219215980462331830553327416887204434813918195854283159012511020564067339731035811005152434161553460108856012385377718821130777993532002330479610147442583636071921565046942503734208375250806650616658158948720491179968591639648500635908770118304874799780887753749949451580451605050915399856582470818645113537935804992115981085766051992433352114352390148795699609591288891602992641511063466313393663477586513029371762047325631781485664350872122828637642044846811407613911477062801689853244110024161447421618567166150540154285084716752901903161322778896729707373123334086988983175067838846926092773977972858659654941091369095406136467568702398678315290680984617210924625396728515625E-308",
235
- MIN_N.nio_write(fmt)
236
- assert_equal "2.2250738585072008890245868760858598876504231122409594654935248025624400092282356951787758888037591552642309780950434312085877387158357291821993020294379224223559819827501242041788969571311791082261043971979604000454897391938079198936081525613113376149842043271751033627391549782731594143828136275113838604094249464942286316695429105080201815926642134996606517803095075913058719846423906068637102005108723282784678843631944515866135041223479014792369585208321597621066375401613736583044193603714778355306682834535634005074073040135602968046375918583163124224521599262546494300836851861719422417646455137135420132217031370496583210154654068035397417906022589503023501937519773030945763173210852507299305089761582519159720757232455434770912461317493580281734466552734375E-308",
237
- MAX_D.nio_write(fmt)
238
- assert_equal "2.225073858507200394958941034839315711081630244019587100433722188237675583642553194503268618595007289964394616459051051412023043270117998255542591673498126023581185971968246077878183766819774580380287229348978296356771103136809189170558146173902184049999817014701706089569539838241444028984739501272818269238398287937541863482503350197395249647392622007205322474852963190178391854932391064931720791430455764953943127215325436859833344767109289929102154994338687742727610729450624487971196675896144263447425089844325111161570498002959146187656616550482084690619235135756396957006047593447154776156167693340095043268338435252390549256952840748419828640113148805198563919935252207510837343961185884248936392555587988206944151446491086954182492263498716056346893310546875E-308",
239
- prv(MAX_D).nio_write(fmt)
240
- assert_equal "9.88131291682493088353137585736442744730119605228649528851171365001351014540417503730599672723271984759593129390891435461853313420711879592797549592021563756252601426380622809055691634335697964207377437272113997461446100012774818307129968774624946794546339230280063430770796148252477131182342053317113373536374079120621249863890543182984910658610913088802254960259419999083863978818160833126649049514295738029453560318710477223100269607052986944038758053621421498340666445368950667144166486387218476578691673612021202301233961950615668455463665849580996504946155275185449574931216955640746893939906729403594535543517025132110239826300978220290207572547633450191167477946719798732961988232841140527418055848553508913045817507736501283943653106689453125E-324",
241
- nxt(MIN_D).nio_write(fmt)
242
- assert_equal "4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625E-324",
243
- MIN_D.nio_write(fmt)
244
-
245
- end
246
-
247
- def test_float_nonsig
248
-
249
- assert_equal "100.000000000000000#####", 100.0.nio_write(Fmt.prec(20,:fix).insignificant_digits('#'))
250
-
251
- fmt = Fmt.mode(:sci,20).insignificant_digits('#').sci_digits(1)
252
- assert_equal "3.3333333333333331###E-1", (1.0/3).nio_write(fmt)
253
- assert_equal "3.3333333333333335###E6", (1E7/3).nio_write(fmt)
254
- assert_equal "3.3333333333333334###E-8", (1E-7/3).nio_write(fmt)
255
- assert_equal "3.3333333333333333333E-1", Rational(1,3).nio_write(fmt)
256
- assert_equal "3.3333333333333331###E-1", (1.0/3).nio_write(fmt.dup.sci_digits(1))
257
- assert_equal "33333333333333331###.E-20", (1.0/3).nio_write(fmt.dup.sci_digits(-1))
258
- assert_equal "33333333333333333333.E-20", (Rational(1,3)).nio_write(fmt.dup.sci_digits(-1))
259
-
260
- fmt.sci_digits! :eng
261
- assert_equal "333.33333333333331###E-3", (1.0/3).nio_write(fmt)
262
- assert_equal "3.3333333333333335###E6", (1E7/3).nio_write(fmt)
263
- assert_equal "33.333333333333334###E-9",(1E-7/3).nio_write(fmt)
264
-
265
- fmt = Fmt[:comma].mode(:sci,20).insignificant_digits('#').sci_digits(0)
266
- assert_equal "0,33333333333333331###E0",(1.0/3).nio_write(fmt)
267
- assert_equal "0,33333333333333335###E7",(1E7/3).nio_write(fmt)
268
- assert_equal "0,33333333333333334###E-7",(1E-7/3).nio_write(fmt)
269
-
270
- fmt = Fmt.mode(:sci,20).insignificant_digits('#').sci_digits(0)
271
- assert_equal "0.10000000000000001###E0",(1E-1).nio_write(fmt)
272
- assert_equal "0.50000000000000000###E0",(0.5).nio_write(fmt)
273
- assert_equal "0.49999999999999994###E0",prv(0.5).nio_write(fmt)
274
- assert_equal "0.50000000000000011###E0",nxt(0.5).nio_write(fmt)
275
- assert_equal "0.22250738585072014###E-307",MIN_N.nio_write(fmt)
276
- assert_equal "0.22250738585072009###E-307",MAX_D.nio_write(fmt)
277
- assert_equal "0.5###################E-323",MIN_D.nio_write(fmt)
278
- assert_equal "0.64000000000000000###E2",(64.0).nio_write(fmt)
279
- assert_equal "0.6400000000000001####E2",(nxt(64.0)).nio_write(fmt)
280
- assert_equal "0.6409999999999999####E2",(64.1).nio_write(fmt)
281
- assert_equal "0.6412312300000001####E2",(64.123123).nio_write(fmt)
282
- assert_equal "0.10000000000000001###E0",(0.1).nio_write(fmt)
283
- assert_equal "0.6338253001141148####E30",nxt(Math.ldexp(0.5,100)).nio_write(fmt)
284
- assert_equal "0.39443045261050599###E-30",nxt(Math.ldexp(0.5,-100)).nio_write(fmt)
285
- assert_equal "0.10##################E-322",nxt(MIN_D).nio_write(fmt)
286
- assert_equal "0.15##################E-322",nxt(nxt(MIN_D)).nio_write(fmt)
287
-
288
- # note: 1E23 is equidistant from 2 Floats; one or the other will be chosen based on the rounding mode
289
- x = Float.nio_read('1E23',Fmt.prec(:exact,:gen,:round=>:even))
290
- assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
291
- assert_equal "9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
292
- assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
293
-
294
- x = Float.nio_read('1E23',Fmt.prec(:exact,:gen,:round=>:zero))
295
- assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
296
- assert_equal "9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
297
- assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
298
-
299
- x = Float.nio_read('1E23',Fmt.prec(:exact,:gen,:round=>:inf))
300
- assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
301
- assert_equal "1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
302
- assert_equal "1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
303
-
304
- x = Float.nio_read('-1E23',Fmt.prec(:exact,:gen,:round=>:even))
305
- assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
306
- assert_equal "-9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
307
- assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
308
-
309
- x = Float.nio_read('-1E23',Fmt.prec(:exact,:gen,:round=>:zero))
310
- assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
311
- assert_equal "-9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
312
- assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
313
-
314
- x = Float.nio_read('-1E23',Fmt.prec(:exact,:gen,:round=>:inf))
315
- assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
316
- assert_equal "-1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
317
- assert_equal "-1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
318
-
319
- # note: for 64.1 there's only one closest Float;
320
- # but it can be univocally expressed in decimal either as 64.09999999999999 or 64.1
321
- x = Float.nio_read('64.1',Fmt.prec(:exact,:gen,:round=>:even))
322
- assert_equal "64.09999999999999",x.nio_write(Fmt.prec(:exact,:gen).show_all_digits(true))
323
- assert_equal "64.1",x.nio_write(Fmt.prec(:exact,:gen))
324
-
325
- # to do: exact conversion of Rational(32095022417, 54517) should throw and exception
326
- # (unless RepDec.max_d is greater than 27300 or so)
327
-
328
-
329
- end
330
-
331
- def test_special
332
- assert BigDecimal.nio_read("NaN").nan?
333
- assert Float.nio_read("NaN").nan?
334
- assert_equal "NAN", BigDec("NaN").nio_write.upcase
335
- assert_equal "NAN", BigDecimal.nio_read("NaN").nio_write.upcase
336
- assert_equal "NAN", Float.nio_read("NaN").nio_write.upcase
337
- assert_raises ZeroDivisionError do Rational.nio_read("NaN") end
338
-
339
- assert !BigDecimal.nio_read('Infinity').finite?
340
- assert !BigDecimal.nio_read('+Infinity').finite?
341
- assert !BigDecimal.nio_read('-Infinity').finite?
342
- assert !Float.nio_read('Infinity').finite?
343
- assert !Float.nio_read('+Infinity').finite?
344
- assert !Float.nio_read('-Infinity').finite?
345
- assert_raises ZeroDivisionError do Rational.nio_read("Infinity") end
346
- assert_raises ZeroDivisionError do Rational.nio_read("+Infinity") end
347
- assert_raises ZeroDivisionError do Rational.nio_read("-Infinity") end
348
- assert_equal BigDec(1)/0, BigDecimal.nio_read('Infinity')
349
- assert_equal BigDec(-1)/0, BigDecimal.nio_read('-Infinity')
350
- assert_equal '+Infinity', BigDecimal.nio_read('Infinity').nio_write
351
- assert_equal '+Infinity', BigDecimal.nio_read('+Infinity').nio_write
352
- assert_equal '-Infinity', BigDecimal.nio_read('-Infinity').nio_write
353
- assert_equal '+Infinity', Float.nio_read('Infinity').nio_write
354
- assert_equal '+Infinity', Float.nio_read('+Infinity').nio_write
355
- assert_equal '-Infinity', Float.nio_read('-Infinity').nio_write
356
-
357
- end
358
-
359
- def test_conversions
360
- x_txt = '1.234567890123456'
361
- x_d = BigDecimal.nio_read(x_txt)
362
- x_f = Float.nio_read(x_txt)
363
- assert_equal 1.234567890123456, x_f
364
- assert_equal BigDecimal(x_txt), x_d
365
- assert_equal Nio.convert(x_d,Float,:exact), x_f
366
- assert_equal Nio.convert(x_d,Float,:approx), x_f
367
-
368
- x_d = BigDec(355)/226
369
- x_f = Float(355)/226
370
- assert_equal Nio.convert(x_d,Float,:exact), x_f
371
- assert_equal Nio.convert(x_d,Float,:approx), x_f
372
-
373
- end
374
-
375
-
376
- end
1
+
2
+
3
+ # Copyright (C) 2003-2005, Javier Goizueta <javier@goizueta.info>
4
+ #
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License
7
+ # as published by the Free Software Foundation; either version 2
8
+ # of the License, or (at your option) any later version.
9
+
10
+ #require File.dirname(__FILE__) + '/test_helper.rb'
11
+ require 'test/unit'
12
+ require 'nio/rtnlzr'
13
+ require 'nio/repdec'
14
+ require 'nio/fmt'
15
+ include Nio
16
+ require 'yaml'
17
+
18
+ def neighbours(x)
19
+ f,e = Math.frexp(x)
20
+ e = Float::MIN_EXP if f==0
21
+ e = [Float::MIN_EXP,e].max
22
+ dx = Math.ldexp(1,e-Float::MANT_DIG) #Math.ldexp(Math.ldexp(1.0,-Float::MANT_DIG),e)
23
+ high = x + dx
24
+ if e==Float::MIN_EXP || f!=0.5 #0.5==Math.ldexp(2**(bits-1),-Float::MANT_DIG)
25
+ low = x - dx
26
+ else
27
+ low = x - dx/2 # x - Math.ldexp(Math.ldexp(1.0,-Float::MANT_DIG),e-1)
28
+ end
29
+ [low, high]
30
+ end
31
+
32
+ def prv(x)
33
+ neighbours(x)[0]
34
+ end
35
+ def nxt(x)
36
+ neighbours(x)[1]
37
+ end
38
+ MIN_N = Math.ldexp(0.5,Float::MIN_EXP) # == nxt(MAX_D) == Float::MIN
39
+ MAX_D = Math.ldexp(Math.ldexp(1,Float::MANT_DIG-1)-1,Float::MIN_EXP-Float::MANT_DIG)
40
+ MIN_D = Math.ldexp(1,Float::MIN_EXP-Float::MANT_DIG);
41
+
42
+ class TestFmt < Test::Unit::TestCase
43
+
44
+ def setup
45
+
46
+ $data = YAML.load(File.read(File.join(File.dirname(__FILE__) ,'data.yaml'))).collect{|x| [x].pack('H*').unpack('E')[0]}
47
+ $data << MIN_N
48
+ $data << MAX_D
49
+ $data << MIN_D
50
+
51
+ end
52
+
53
+ def teardown
54
+
55
+ Fmt.default = Fmt.new
56
+
57
+ end
58
+
59
+
60
+ def test_basic_fmt
61
+ # test correct rounding: 1.448997445238699 -> 6525704354437805*2^-52
62
+ assert_equal Rational(6525704354437805,4503599627370496), Float.nio_read('1.448997445238699').nio_xr
63
+
64
+ assert_equal "0",0.0.nio_write
65
+ assert_equal "0",0.nio_write
66
+ assert_equal "0",BigDecimal('0').nio_write
67
+ assert_equal "0",Rational(0,1).nio_write
68
+
69
+ assert_equal "123456789",123456789.0.nio_write
70
+ assert_equal "123456789",123456789.nio_write
71
+ assert_equal "123456789",BigDecimal('123456789').nio_write
72
+ assert_equal "123456789",Rational(123456789,1).nio_write
73
+ assert_equal "123456789.25",123456789.25.nio_write
74
+ assert_equal "123456789.25",BigDecimal('123456789.25').nio_write
75
+ assert_equal "123456789.25",(Rational(123456789)+Rational(1,4)).nio_write
76
+ end
77
+
78
+ def test_basic_fmt_float
79
+
80
+ assert_equal 2,Float::RADIX
81
+ assert_equal 53,Float::MANT_DIG
82
+
83
+ fmt = Fmt.new {|f|
84
+ f.rep! '[','','...',0,true
85
+ f.width! 20,:right,'*'
86
+ }
87
+ fmt.sep! '.',',',[3]
88
+
89
+ assert_equal "0.1",0.1.nio_write
90
+ assert_equal "0.10000000000000001",0.1.nio_write(Fmt.mode(:gen,:exact).show_all_digits)
91
+ assert_equal "0.10000000000000001",0.1.nio_write(Fmt.mode(:gen,:exact).show_all_digits(true))
92
+ assert_equal "0.10000000000000001",0.1.nio_write(Fmt.mode(:gen,:exact,:show_all_digits=>true))
93
+ assert_equal "0.1000000000000000055511151231257827021181583404541015625",0.1.nio_write(Fmt.mode(:gen,:exact,:approx=>:exact))
94
+
95
+
96
+ assert_equal "******643,454,333.32",fmt.nio_write_formatted(fmt.nio_read_formatted("643,454,333.32"))
97
+ assert_equal "******643.454.333,32",fmt.sep(',').nio_write_formatted(fmt.nio_read_formatted("643,454,333.32"))
98
+ fmt.pad0s! 10
99
+ num = fmt.nio_read_formatted("0.3333...")
100
+ assert_equal "0000000.[3",fmt.nio_write_formatted(num)
101
+ fmt.mode! :fix, 3
102
+ assert_equal "000000.333",fmt.nio_write_formatted(num)
103
+ num = fmt.nio_read_formatted("-0.666...")
104
+ fmt.prec! :exact
105
+ fmt.sep! ',','.'
106
+ assert_equal "-000000,[6",fmt.nio_write_formatted(num)
107
+ fmt.width! 20,:center,'*'
108
+ fmt.mode! :fix,3
109
+ assert_equal "*******-0,667*******",fmt.nio_write_formatted(num)
110
+ num = fmt.nio_read_formatted("0,5555")
111
+ fmt.prec! :exact
112
+ assert_equal "*******0,5555*******",fmt.nio_write_formatted(num)
113
+
114
+ Fmt.default = Fmt[:comma_th]
115
+ x = Float.nio_read("11123,2343")
116
+ assert_equal 11123.2343,x
117
+ assert_equal "11.123,2343", x.nio_write
118
+ assert_equal "11123,2343", x.nio_write(Fmt[:comma])
119
+
120
+ x = Float.nio_read("-1234,5678901234e-33")
121
+ # assert_equal -1.2345678901234e-030, x
122
+ assert_equal "-1,2345678901234E-30", x.nio_write()
123
+ assert_equal "-0,0000000000000000000000000000012346",x.nio_write(Fmt[:comma].mode(:sig,5))
124
+
125
+ assert_equal "0,333...",
126
+ (1.0/3).nio_write(Fmt.prec(:exact).show_all_digits(true).approx_mode(:simplify))
127
+
128
+ fmt = Fmt.default
129
+ if RUBY_VERSION>='1.9.0'
130
+ assert_raises RuntimeError do fmt.prec! 4 end
131
+ else
132
+ assert_raises TypeError do fmt.prec! 4 end
133
+ end
134
+ fmt = Fmt.default {|f| f.prec! 4 }
135
+ assert_equal "1,235", 1.23456.nio_write(fmt)
136
+ assert_equal "1,23456", 1.23456.nio_write()
137
+
138
+ Fmt.default = Fmt.new
139
+ assert_equal '11123.2343', 11123.2343.nio_write
140
+ end
141
+
142
+ def test_tol_fmt_float
143
+ tol = Tolerance.new.decimals(12,:sig)
144
+ fmt = Fmt.prec(12,:sig)
145
+ $data.each do |x|
146
+ assert tol.equals?(x, Float.nio_read(x.nio_write(fmt),fmt)), "out of tolerance: #{x.inspect} #{Float.nio_read(x.nio_write(fmt),fmt)}"
147
+ assert tol.equals?(-x, Float.nio_read((-x).nio_write(fmt),fmt)), "out of tolerance: #{(-x).inspect} #{Float.nio_read((-x).nio_write(fmt),fmt)}"
148
+ end
149
+ end
150
+
151
+ def test_BigDec
152
+ assert_equal "0",BigDec(0).nio_write
153
+ fmt = Fmt.mode(:gen,:exact)
154
+ assert_equal "0",BigDec(0).nio_write(fmt)
155
+ $data.each do |x|
156
+ x = BigDecimal(x.to_s)
157
+ assert_equal x,BigDecimal.nio_read(x.nio_write(fmt),fmt)
158
+ end
159
+ assert_equal "1E500",BigDec('1E500').nio_write
160
+ assert_equal "1E-500",BigDec('1E-500').nio_write
161
+ assert_equal "-1E500",BigDec('-1E500').nio_write
162
+ assert_equal "-1E-500",BigDec('-1E-500').nio_write
163
+ end
164
+
165
+ def test_Rational
166
+ assert_equal "0",Rational(0,1).nio_write
167
+ fmt = Fmt.mode(:gen,:exact)
168
+ assert_equal "0",Rational(0,1).nio_write(fmt)
169
+ $data.each do |x|
170
+ x = x.nio_xr # nio_r
171
+ assert_equal x,Rational.nio_read(x.nio_write(fmt),fmt)
172
+ end
173
+ end
174
+
175
+ def test_float_bases
176
+ nfmt2 = Fmt[:comma].base(2).prec(:exact)
177
+ nfmt8 = Fmt[:comma].base(8).prec(:exact)
178
+ nfmt10 = Fmt[:comma].base(10).prec(:exact)
179
+ nfmt16 = Fmt[:comma].base(16).prec(:exact)
180
+ $data.each do |x|
181
+ assert_equal(x,Float.nio_read(x.nio_write(nfmt2),nfmt2))
182
+ assert_equal(x,Float.nio_read(x.nio_write(nfmt8),nfmt8))
183
+ assert_equal(x,Float.nio_read(x.nio_write(nfmt10),nfmt10))
184
+ assert_equal(x,Float.nio_read(x.nio_write(nfmt16),nfmt16))
185
+ assert_equal(-x,Float.nio_read((-x).nio_write(nfmt2),nfmt2))
186
+ assert_equal(-x,Float.nio_read((-x).nio_write(nfmt8),nfmt8))
187
+ assert_equal(-x,Float.nio_read((-x).nio_write(nfmt10),nfmt10))
188
+ assert_equal(-x,Float.nio_read((-x).nio_write(nfmt16),nfmt16))
189
+ end
190
+ end
191
+
192
+ def rational_bases
193
+ assert_equal "0.0001100110011...", (Rational(1)/10).nio_write(Fmt.new.base(2))
194
+ end
195
+
196
+ def test_big_decimal_bases
197
+
198
+ assert_equal "0.1999A",(BigDec(1)/10).nio_write(Fmt.new.base(16).prec(5))
199
+ assert_equal "0.1999...",(BigDec(1)/10).nio_write(Fmt.mode(:gen,:exact,:round=>:inf,:approx=>:simplify).base(16))
200
+
201
+ nfmt2 = Fmt[:comma].base(2).prec(:exact)
202
+ nfmt8 = Fmt[:comma].base(8).prec(:exact)
203
+ nfmt10 = Fmt[:comma].base(10).prec(:exact)
204
+ nfmt16 = Fmt[:comma].base(16).prec(:exact)
205
+ $data.each do |x|
206
+ x = BigDec(x.to_s)
207
+ xs,xdig,xb,xe = x.split
208
+ ndig = xdig.size
209
+ round_dig = ndig-xe
210
+ # note that BigDecimal.nio_read produces a BigDecimal with the exact value of the text representation
211
+ # since the representation here is only aproximate (because of the base difference), we must
212
+ # round the results to the precision of the original number
213
+ assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt2),nfmt2).round(round_dig))
214
+ assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt8),nfmt8).round(round_dig))
215
+ assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt10),nfmt10).round(round_dig))
216
+ assert_equal(x,BigDecimal.nio_read(x.nio_write(nfmt16),nfmt16).round(round_dig))
217
+ assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt2),nfmt2).round(round_dig))
218
+ assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt8),nfmt8).round(round_dig))
219
+ assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt10),nfmt10).round(round_dig))
220
+ assert_equal(-x,BigDecimal.nio_read((-x).nio_write(nfmt16),nfmt16).round(round_dig))
221
+ end
222
+ end
223
+
224
+ def test_exact_all_float
225
+ #fmt = Fmt.prec(:exact).show_all_digits(true).approx_mode(:exact)
226
+ fmt = Fmt.mode(:gen,:exact,:round=>:inf,:approx=>:exact)
227
+ assert_equal "0.1000000000000000055511151231257827021181583404541015625",Float.nio_read('0.1',fmt).nio_write(fmt)
228
+ assert_equal "64.099999999999994315658113919198513031005859375",Float.nio_read('64.1',fmt).nio_write(fmt)
229
+ assert_equal '0.5',Float.nio_read('0.5',fmt).nio_write(fmt)
230
+ assert_equal "0.333333333333333314829616256247390992939472198486328125", (1.0/3.0).nio_write(fmt)
231
+ assert_equal "0.66666666666666662965923251249478198587894439697265625", (2.0/3.0).nio_write(fmt)
232
+ assert_equal "-0.333333333333333314829616256247390992939472198486328125", (-1.0/3.0).nio_write(fmt)
233
+ assert_equal "-0.66666666666666662965923251249478198587894439697265625", (-2.0/3.0).nio_write(fmt)
234
+ assert_equal "1267650600228229401496703205376", (2.0**100).nio_write(fmt)
235
+ assert_equal "0.10000000000000001942890293094023945741355419158935546875", nxt(0.1).nio_write(fmt)
236
+ assert_equal "1023.9999999999998863131622783839702606201171875", prv(1024).nio_write(fmt)
237
+
238
+ assert_equal "2.225073858507201383090232717332404064219215980462331830553327416887204434813918195854283159012511020564067339731035811005152434161553460108856012385377718821130777993532002330479610147442583636071921565046942503734208375250806650616658158948720491179968591639648500635908770118304874799780887753749949451580451605050915399856582470818645113537935804992115981085766051992433352114352390148795699609591288891602992641511063466313393663477586513029371762047325631781485664350872122828637642044846811407613911477062801689853244110024161447421618567166150540154285084716752901903161322778896729707373123334086988983175067838846926092773977972858659654941091369095406136467568702398678315290680984617210924625396728515625E-308",
239
+ MIN_N.nio_write(fmt)
240
+ assert_equal "2.2250738585072008890245868760858598876504231122409594654935248025624400092282356951787758888037591552642309780950434312085877387158357291821993020294379224223559819827501242041788969571311791082261043971979604000454897391938079198936081525613113376149842043271751033627391549782731594143828136275113838604094249464942286316695429105080201815926642134996606517803095075913058719846423906068637102005108723282784678843631944515866135041223479014792369585208321597621066375401613736583044193603714778355306682834535634005074073040135602968046375918583163124224521599262546494300836851861719422417646455137135420132217031370496583210154654068035397417906022589503023501937519773030945763173210852507299305089761582519159720757232455434770912461317493580281734466552734375E-308",
241
+ MAX_D.nio_write(fmt)
242
+ assert_equal "2.225073858507200394958941034839315711081630244019587100433722188237675583642553194503268618595007289964394616459051051412023043270117998255542591673498126023581185971968246077878183766819774580380287229348978296356771103136809189170558146173902184049999817014701706089569539838241444028984739501272818269238398287937541863482503350197395249647392622007205322474852963190178391854932391064931720791430455764953943127215325436859833344767109289929102154994338687742727610729450624487971196675896144263447425089844325111161570498002959146187656616550482084690619235135756396957006047593447154776156167693340095043268338435252390549256952840748419828640113148805198563919935252207510837343961185884248936392555587988206944151446491086954182492263498716056346893310546875E-308",
243
+ prv(MAX_D).nio_write(fmt)
244
+ assert_equal "9.88131291682493088353137585736442744730119605228649528851171365001351014540417503730599672723271984759593129390891435461853313420711879592797549592021563756252601426380622809055691634335697964207377437272113997461446100012774818307129968774624946794546339230280063430770796148252477131182342053317113373536374079120621249863890543182984910658610913088802254960259419999083863978818160833126649049514295738029453560318710477223100269607052986944038758053621421498340666445368950667144166486387218476578691673612021202301233961950615668455463665849580996504946155275185449574931216955640746893939906729403594535543517025132110239826300978220290207572547633450191167477946719798732961988232841140527418055848553508913045817507736501283943653106689453125E-324",
245
+ nxt(MIN_D).nio_write(fmt)
246
+ assert_equal "4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625E-324",
247
+ MIN_D.nio_write(fmt)
248
+
249
+ end
250
+
251
+ def test_float_nonsig
252
+
253
+ assert_equal "100.000000000000000#####", 100.0.nio_write(Fmt.prec(20,:fix).insignificant_digits('#'))
254
+
255
+ fmt = Fmt.mode(:sci,20).insignificant_digits('#').sci_digits(1)
256
+ assert_equal "3.3333333333333331###E-1", (1.0/3).nio_write(fmt)
257
+ assert_equal "3.3333333333333335###E6", (1E7/3).nio_write(fmt)
258
+ assert_equal "3.3333333333333334###E-8", (1E-7/3).nio_write(fmt)
259
+ assert_equal "3.3333333333333333333E-1", Rational(1,3).nio_write(fmt)
260
+ assert_equal "3.3333333333333331###E-1", (1.0/3).nio_write(fmt.dup.sci_digits(1))
261
+ assert_equal "33333333333333331###.E-20", (1.0/3).nio_write(fmt.dup.sci_digits(-1))
262
+ assert_equal "33333333333333333333.E-20", (Rational(1,3)).nio_write(fmt.dup.sci_digits(-1))
263
+
264
+ fmt.sci_digits! :eng
265
+ assert_equal "333.33333333333331###E-3", (1.0/3).nio_write(fmt)
266
+ assert_equal "3.3333333333333335###E6", (1E7/3).nio_write(fmt)
267
+ assert_equal "33.333333333333334###E-9",(1E-7/3).nio_write(fmt)
268
+
269
+ fmt = Fmt[:comma].mode(:sci,20).insignificant_digits('#').sci_digits(0)
270
+ assert_equal "0,33333333333333331###E0",(1.0/3).nio_write(fmt)
271
+ assert_equal "0,33333333333333335###E7",(1E7/3).nio_write(fmt)
272
+ assert_equal "0,33333333333333334###E-7",(1E-7/3).nio_write(fmt)
273
+
274
+ fmt = Fmt.mode(:sci,20).insignificant_digits('#').sci_digits(0)
275
+ assert_equal "0.10000000000000001###E0",(1E-1).nio_write(fmt)
276
+ assert_equal "0.50000000000000000###E0",(0.5).nio_write(fmt)
277
+ assert_equal "0.49999999999999994###E0",prv(0.5).nio_write(fmt)
278
+ assert_equal "0.50000000000000011###E0",nxt(0.5).nio_write(fmt)
279
+ assert_equal "0.22250738585072014###E-307",MIN_N.nio_write(fmt)
280
+ assert_equal "0.22250738585072009###E-307",MAX_D.nio_write(fmt)
281
+ assert_equal "0.5###################E-323",MIN_D.nio_write(fmt)
282
+ assert_equal "0.64000000000000000###E2",(64.0).nio_write(fmt)
283
+ assert_equal "0.6400000000000001####E2",(nxt(64.0)).nio_write(fmt)
284
+ assert_equal "0.6409999999999999####E2",(64.1).nio_write(fmt)
285
+ assert_equal "0.6412312300000001####E2",(64.123123).nio_write(fmt)
286
+ assert_equal "0.10000000000000001###E0",(0.1).nio_write(fmt)
287
+ assert_equal "0.6338253001141148####E30",nxt(Math.ldexp(0.5,100)).nio_write(fmt)
288
+ assert_equal "0.39443045261050599###E-30",nxt(Math.ldexp(0.5,-100)).nio_write(fmt)
289
+ assert_equal "0.10##################E-322",nxt(MIN_D).nio_write(fmt)
290
+ assert_equal "0.15##################E-322",nxt(nxt(MIN_D)).nio_write(fmt)
291
+
292
+ # note: 1E23 is equidistant from 2 Floats; one or the other will be chosen based on the rounding mode
293
+ x = Float.nio_read('1E23',Fmt.prec(:exact,:gen,:round=>:even))
294
+ assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
295
+ assert_equal "9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
296
+ assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
297
+
298
+ x = Float.nio_read('1E23',Fmt.prec(:exact,:gen,:round=>:zero))
299
+ assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
300
+ assert_equal "9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
301
+ assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
302
+
303
+ x = Float.nio_read('1E23',Fmt.prec(:exact,:gen,:round=>:inf))
304
+ assert_equal "1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
305
+ assert_equal "1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
306
+ assert_equal "1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
307
+
308
+ x = Float.nio_read('-1E23',Fmt.prec(:exact,:gen,:round=>:even))
309
+ assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
310
+ assert_equal "-9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
311
+ assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
312
+
313
+ x = Float.nio_read('-1E23',Fmt.prec(:exact,:gen,:round=>:zero))
314
+ assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
315
+ assert_equal "-9.999999999999999E22",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
316
+ assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
317
+
318
+ x = Float.nio_read('-1E23',Fmt.prec(:exact,:gen,:round=>:inf))
319
+ assert_equal "-1E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:inf))
320
+ assert_equal "-1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:zero))
321
+ assert_equal "-1.0000000000000001E23",x.nio_write(Fmt.prec(:exact,:gen,:round=>:even))
322
+
323
+ # note: for 64.1 there's only one closest Float;
324
+ # but it can be univocally expressed in decimal either as 64.09999999999999 or 64.1
325
+ x = Float.nio_read('64.1',Fmt.prec(:exact,:gen,:round=>:even))
326
+ assert_equal "64.09999999999999",x.nio_write(Fmt.prec(:exact,:gen).show_all_digits(true))
327
+ assert_equal "64.1",x.nio_write(Fmt.prec(:exact,:gen))
328
+
329
+ # to do: exact conversion of Rational(32095022417, 54517) should throw and exception
330
+ # (unless RepDec.max_d is greater than 27300 or so)
331
+
332
+
333
+ end
334
+
335
+ def test_special
336
+ assert BigDecimal.nio_read("NaN").nan?
337
+ assert Float.nio_read("NaN").nan?
338
+ assert_equal "NAN", BigDec("NaN").nio_write.upcase
339
+ assert_equal "NAN", BigDecimal.nio_read("NaN").nio_write.upcase
340
+ assert_equal "NAN", Float.nio_read("NaN").nio_write.upcase
341
+ assert_raises ZeroDivisionError do Rational.nio_read("NaN") end
342
+
343
+ assert !BigDecimal.nio_read('Infinity').finite?
344
+ assert !BigDecimal.nio_read('+Infinity').finite?
345
+ assert !BigDecimal.nio_read('-Infinity').finite?
346
+ assert !Float.nio_read('Infinity').finite?
347
+ assert !Float.nio_read('+Infinity').finite?
348
+ assert !Float.nio_read('-Infinity').finite?
349
+ assert_raises ZeroDivisionError do Rational.nio_read("Infinity") end
350
+ assert_raises ZeroDivisionError do Rational.nio_read("+Infinity") end
351
+ assert_raises ZeroDivisionError do Rational.nio_read("-Infinity") end
352
+ assert_equal BigDec(1)/0, BigDecimal.nio_read('Infinity')
353
+ assert_equal BigDec(-1)/0, BigDecimal.nio_read('-Infinity')
354
+ assert_equal '+Infinity', BigDecimal.nio_read('Infinity').nio_write
355
+ assert_equal '+Infinity', BigDecimal.nio_read('+Infinity').nio_write
356
+ assert_equal '-Infinity', BigDecimal.nio_read('-Infinity').nio_write
357
+ assert_equal '+Infinity', Float.nio_read('Infinity').nio_write
358
+ assert_equal '+Infinity', Float.nio_read('+Infinity').nio_write
359
+ assert_equal '-Infinity', Float.nio_read('-Infinity').nio_write
360
+
361
+ end
362
+
363
+ def test_conversions
364
+ x_txt = '1.234567890123456'
365
+ x_d = BigDecimal.nio_read(x_txt)
366
+ x_f = Float.nio_read(x_txt)
367
+ assert_equal 1.234567890123456, x_f
368
+ assert_equal BigDecimal(x_txt), x_d
369
+ assert_equal Fmt.convert(x_d,Float,:exact), x_f
370
+ assert_equal Fmt.convert(x_d,Float,:approx), x_f
371
+
372
+ x_d = BigDec(355)/226
373
+ x_f = Float(355)/226
374
+ assert_equal Fmt.convert(x_d,Float,:exact), x_f
375
+ assert_equal Fmt.convert(x_d,Float,:approx), x_f
376
+
377
+ end
378
+
379
+ def test_sign
380
+ assert_equal '1.23', 1.23.nio_write
381
+ assert_equal '+1.23', 1.23.nio_write(Fmt.show_plus)
382
+ assert_equal ' 1.23', 1.23.nio_write(Fmt.show_plus(' '))
383
+ assert_equal '-1.23', -1.23.nio_write
384
+ assert_equal '-1.23', -1.23.nio_write(Fmt.show_plus)
385
+ assert_equal '1.23E5', 1.23E5.nio_write(Fmt.mode(:sci))
386
+ assert_equal '-1.23E5', -1.23E5.nio_write(Fmt.mode(:sci))
387
+ assert_equal '1.23E-5', 1.23E-5.nio_write(Fmt.mode(:sci))
388
+ assert_equal '-1.23E-5', -1.23E-5.nio_write(Fmt.mode(:sci))
389
+ assert_equal '+1.23E5', 1.23E5.nio_write(Fmt.mode(:sci).show_plus)
390
+ assert_equal '-1.23E5', -1.23E5.nio_write(Fmt.mode(:sci).show_plus)
391
+ assert_equal ' 1.23E5', 1.23E5.nio_write(Fmt.mode(:sci).show_plus(' '))
392
+ assert_equal '-1.23E5', -1.23E5.nio_write(Fmt.mode(:sci).show_plus(' '))
393
+ assert_equal '1.23E+5', 1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus)
394
+ assert_equal '-1.23E+5', -1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus)
395
+ assert_equal '1.23E 5', 1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus(' '))
396
+ assert_equal '-1.23E 5', -1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus(' '))
397
+ assert_equal '1.23E-5', 1.23E-5.nio_write(Fmt.mode(:sci).show_exp_plus(' '))
398
+ assert_equal '-1.23E-5', -1.23E-5.nio_write(Fmt.mode(:sci).show_exp_plus(' '))
399
+ assert_equal ' 1.23E-5', 1.23E-5.nio_write(Fmt.mode(:sci).show_exp_plus(' ').show_plus)
400
+ assert_equal '-1.23E-5', -1.23E-5.nio_write(Fmt.mode(:sci).show_exp_plus(' ').show_plus)
401
+ assert_equal ' 1.23E 5', 1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus(' ').show_plus)
402
+ assert_equal '-1.23E 5', -1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus(' ').show_plus)
403
+ assert_equal '+1.23E-5', 1.23E-5.nio_write(Fmt.mode(:sci).show_exp_plus.show_plus)
404
+ assert_equal '-1.23E-5', -1.23E-5.nio_write(Fmt.mode(:sci).show_exp_plus.show_plus)
405
+ assert_equal '+1.23E+5', 1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus.show_plus)
406
+ assert_equal '-1.23E+5', -1.23E5.nio_write(Fmt.mode(:sci).show_exp_plus.show_plus)
407
+ end
408
+
409
+
410
+ end