numerals 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2db2456e26dc108b6ffc0e72616b58c94c00eee
4
- data.tar.gz: 4150c883baaa50b85c7f9f7619b5bde35ec5ff9e
3
+ metadata.gz: 4a2eebfacb8568be5a073d74a2f7a08eeafafc68
4
+ data.tar.gz: d950941cd533ec4a5dd681446893f0d5f59b5f54
5
5
  SHA512:
6
- metadata.gz: 755fe267a26a4091942e522f32e335cc5d17adfcd3d24a671a09d251927d40bdf7a2fc8f508f27272de8b1dd310ac160d7bf256079d7c9b44df34bb542724661
7
- data.tar.gz: e1d04a258486962b14b0c5c1065d017a20ea09bcb15d551579a55f0db3f0a206ebe7b800ce065ca7e9ca0aff832ecb2a0d357b4390228ed7caa5931b684e4d5c
6
+ metadata.gz: d0b51714327a49c8554ee335010707578909cf129f6a089f50422e34e0a0939c4b7426dd10b305b411326dfc7ac9246a1c342de8236e7ee6d691a3c0f8c0d1dc
7
+ data.tar.gz: a3bd8a43be96700742968d64374fb3a299fdbb111d9fe6b3a2aefe2c14a2f419394e6bc9982fd339113c739bac39ecabd694910ea72b8cbc0bcb0710c19241a0
data/README.md CHANGED
@@ -72,15 +72,17 @@ Specific precision can be obtained like this:
72
72
  But this won't show digits that are insignificant (when the input number
73
73
  is regarded as an approximation):
74
74
 
75
- puts Format[precision: 20].write(0.1) # -> 0.10000000000000001
76
- puts Format[precision: 20].write(Rational(1,10))# -> 0.10000000000000000000
75
+ puts Format[precision: 20].write(0.1) # -> 0.10000000000000001
76
+ puts Format[precision: 20].write(Rational(1,10)) # -> 0.10000000000000000000
77
77
 
78
78
  Although a Float is considered an approximation by default (since
79
79
  it cannot represent arbitrary precision exactly), we can
80
80
  reinterpret it as an exact quantity with the :exact_input Format option:
81
81
 
82
- puts Format[:exact_input, precision: 20].write(0.1)# -> 0.10000000000000000555
83
- puts Format[:exact_input].write(0.1) # -> 0.1000000000000000055511151231257827021181583404541015625
82
+ puts Format[:exact_input, precision: 20].write(0.1)
83
+ # -> 0.10000000000000000555
84
+ puts Format[:exact_input].write(0.1)
85
+ # -> 0.1000000000000000055511151231257827021181583404541015625
84
86
 
85
87
  Rationals are always 'exact' quantities, and they may require infinite
86
88
  digits to be represented exactly in some output bases. This is handled
@@ -104,28 +106,28 @@ will be a variable-precision result based on the input. The default
104
106
  Format, which has :short (simplifying) precision will produce a simple
105
107
  result with as few significant digits as possible:
106
108
 
107
- puts Format[:short].read('1.000', type: Flt::DecNum)# -> 1
108
- puts Format[:short].read('0.100', type: Flt::BinNum)# -> 0.1
109
+ puts Format[:short].read('1.000', type: Flt::DecNum) # -> 1
110
+ puts Format[:short].read('0.100', type: Flt::BinNum) # -> 0.1
109
111
 
110
112
  To retain the precision of the input text, the :free precision should be
111
113
  used:
112
114
 
113
- puts Format[:free].read('1.000', type: Flt::DecNum)# -> 1.000
114
- puts Format[:free].read('0.100', type: Flt::BinNum)# -> 0.1
115
+ puts Format[:free].read('1.000', type: Flt::DecNum) # -> 1.000
116
+ puts Format[:free].read('0.100', type: Flt::BinNum) # -> 0.1
115
117
 
116
118
  As an alternative, the precision implied by the text input can be ignored
117
119
  and the result adjusted to the precision of the destination context. This
118
120
  is done by regarding the input as 'exact'.
119
121
 
120
- puts Format[:exact_input].read('1.000', type: Flt::DecNum)# -> 1.000000000000000000000000000
121
- puts Format[:exact_input].read('0.100', type: Flt::BinNum)# -> 0.1
122
+ puts Format[:exact_input].read('1.000', type: Flt::DecNum) # -> 1.000000000000000000000000000
123
+ puts Format[:exact_input].read('0.100', type: Flt::BinNum) # -> 0.1
122
124
  Flt::DecNum.context.precision = 8
123
- puts Format[:exact_input].read('1.000', type: Flt::DecNum)# -> 1.0000000
125
+ puts Format[:exact_input].read('1.000', type: Flt::DecNum) # -> 1.0000000
124
126
 
125
127
  If the input specifies repeating digits, then it is automatically regarded
126
128
  exact and rounded according to the destination context:
127
129
 
128
- puts Format[:exact_input].read('0.333...', type: Flt::DecNum)# -> 0.33333333
130
+ puts Format[:exact_input].read('0.333...', type: Flt::DecNum) # -> 0.33333333
129
131
 
130
132
  Note that the repeating digits have been automatically detected. This
131
133
  happens because the repeating suffix '...' has ben found (it is defined
@@ -138,13 +140,31 @@ in Symbols, which are <> by default:
138
140
 
139
141
  A Format can also be used to read a formatted number into a Numeral:
140
142
 
141
- puts Format[].read('1.25', type: Numeral) # -> Numeral[1, 2, 5, :sign=>1, :point=>1, :normalize=>:approximate, :base=>10]
142
- puts Format[].read('1.<3>', type: Numeral) # -> Numeral[1, 3, :sign=>1, :point=>1, :repeat=>1, :base=>10]
143
+ puts Format[].read('1.25', type: Numeral)
144
+ # -> Numeral[1, 2, 5, :sign=>1, :point=>1, :normalize=>:approximate, :base=>10]
145
+ puts Format[].read('1.<3>', type: Numeral)
146
+ # -> Numeral[1, 3, :sign=>1, :point=>1, :repeat=>1, :base=>10]
143
147
 
144
148
  Other examples:
145
149
 
146
150
  puts Format[:free, base: 2].read('0.1', type: Flt::DecNum)# -> 0.5
147
151
 
152
+ ## Shortcut notation
153
+
154
+ The `<<` and `>>` operators can be applied to Format objects
155
+ as a shortcut for formatted writing and reading:
156
+
157
+ fmt = Format[]
158
+ puts fmt << 0.1 # -> 0.1
159
+ puts fmt << 0.1 << ' ' << 0.2 << ' ' << [places: 3] << 0.3 # -> 0.1 0.2 0.300
160
+ puts fmt >> '0.1' >> Rational # -> 1/10
161
+
162
+ These operators can also be applied to Format, which is equivalent
163
+ to apply them to de default Format, `Format[]`:
164
+
165
+ puts Format << [:sci, places: 4] << 0.1 # -> 1.000e-1
166
+ puts Format >> '0.1' >> Rational # -> 1/10
167
+
148
168
  Roadmap
149
169
  =======
150
170
 
@@ -11,3 +11,4 @@ require 'numerals/conversions/rational'
11
11
  require 'numerals/conversions/bigdecimal'
12
12
  require 'numerals/conversions/flt'
13
13
  require 'numerals/format'
14
+ require 'numerals/format/sugar'
@@ -77,6 +77,28 @@ module Numerals
77
77
  # Rounding. (in this case the :free and :short precision roundings are
78
78
  # equivalent)
79
79
  #
80
+ # Summary
81
+ #
82
+ # In result there are 5 basically diferent conversion modes.
83
+ # Three of them apply only to approximate values, so they are
84
+ # not available for all input types:
85
+ #
86
+ # * 'Short' mode, which produces an exact Numeral. Used when
87
+ # input is not exact and rounding precision is :short.
88
+ # * 'Free' mode, which produces an approximate Numeral. Used
89
+ # when input is not exact and rounding precision is :short.
90
+ # * 'Fixed' mode, which produces an approximate Numeral. Used when
91
+ # input isnot exact and rounding precision is limited.
92
+ #
93
+ # The other two modes are applied to exact input, so they're
94
+ # available for all input types (since all can be taken as exact with
95
+ # the :exact option):
96
+ #
97
+ # * 'All' mode, which produces an exact Numeral. Used when
98
+ # input is exact and rounding precision is :free (or :short).
99
+ # * 'Rounded' mode, which produces an approximate Numeral. Used
100
+ # when input is exact and rounding precision is limited.
101
+ #
80
102
  def write(number, options = {})
81
103
  output_rounding = Rounding[options[:rounding] || Rounding[]]
82
104
  conversion = self[number.class, options[:type_options]]
@@ -88,6 +110,76 @@ module Numerals
88
110
  self[number.class, options[:type_options]].exact?(number, options)
89
111
  end
90
112
 
113
+ # Convert an number to a different numeric type.
114
+ # Conversion is done by first converting the number to a Numeral,
115
+ # then converting the Numeral to de destination type.
116
+ #
117
+ # Options:
118
+ #
119
+ # * :exact_input Consider the number an exact quantity.
120
+ # Otherwise, for approximate types, insignificant digits
121
+ # will not be converted.
122
+ # * :rounding Rounding to be applied during the conversion.
123
+ # * :type or :context can be used to define the destination
124
+ # type.
125
+ # * :output_mode can have the values :free, :short or :fixed
126
+ # and is used to define how the result is generated.
127
+ #
128
+ def convert(number, options = {})
129
+ if options[:exact]
130
+ options = options.merge(exact_input: true, ouput_mode: :free)
131
+ end
132
+
133
+ exact_input = options[:exact_input] || false
134
+ rounding = Rounding[options[:rounding] || Rounding[]]
135
+ output_mode = options[:output_mode] || :free # :short :free :fixed
136
+ type_options = options[:type_options]
137
+ selector = options[:context] || options[:type]
138
+ output_conversions = self[selector, type_options]
139
+ if output_conversions && output_conversions.respond_to?(:context)
140
+ output_base = output_conversions.context.radix
141
+ if rounding.base != output_base && rounding.free?
142
+ rounding = rounding[base: output_base]
143
+ end
144
+ end
145
+
146
+ if number.is_a?(Numeral)
147
+ numeral = number
148
+ else
149
+ input_options = {
150
+ exact: exact_input,
151
+ rounding: rounding,
152
+ type_options: type_options
153
+ }
154
+ numeral = write(number, input_options)
155
+ end
156
+
157
+ output_options = {
158
+ type: options[:type], context: options[:context]
159
+ }
160
+ case output_mode
161
+ when :short
162
+ output_options.merge!(
163
+ exact: false,
164
+ simplify: true
165
+ )
166
+ when :free
167
+ output_options.merge!(
168
+ exact: false,
169
+ simplify: false
170
+ )
171
+ when :fixed
172
+ output_options.merge!(
173
+ exact: true,
174
+ simplify: false
175
+ )
176
+ end
177
+ if !output_options[:exact] && numeral.exact?
178
+ numeral.approximate!
179
+ end
180
+ read(numeral, output_options)
181
+ end
182
+
91
183
  private
92
184
 
93
185
  def extract_mode_from_args!(args)
@@ -106,6 +106,7 @@ module Numerals
106
106
  end
107
107
  else
108
108
  # akin to @context.Num(numeral_text, :fixed)
109
+ numeral = numeral.exact if exact_input
109
110
  fixed_numeral_to_num numeral
110
111
  end
111
112
  end
@@ -215,7 +216,7 @@ module Numerals
215
216
  if @input_rounding
216
217
  rounding_mode = @input_rounding.mode
217
218
  else
218
- rounding_Mode = @context.rounding
219
+ rounding_Mode = @context.rounding
219
220
  end
220
221
  reader.read(@context, rounding_mode, sign, coefficient, scale, numeral.base).tap do
221
222
  # @exact = reader.exact?
@@ -3,7 +3,22 @@ module Numerals
3
3
  # Formatted input implementation
4
4
  module Format::Input
5
5
 
6
- def read(text, options={})
6
+ def read(*args)
7
+ options = {}
8
+ args.each do |arg|
9
+ case arg
10
+ when String
11
+ options.merge! text: arg
12
+ when Hash
13
+ options.merge! arg
14
+ else
15
+ options.merge! type: arg
16
+ end
17
+ end
18
+
19
+ text = options[:text]
20
+ options[:type] ||= options[:as]
21
+
7
22
  # 1. Obtain destination type
8
23
  selector = options[:context] || options[:type]
9
24
  conversion = Conversions[selector, options[:type_options]]
@@ -0,0 +1,110 @@
1
+ module Numerals
2
+
3
+ class Format
4
+ def self.<<(*args)
5
+ Format[].<<(*args)
6
+ end
7
+
8
+ def self.>>(*args)
9
+ Format[].>>(*args)
10
+ end
11
+
12
+ def <<(*args)
13
+ FormattingStream[self].<<(*args)
14
+ end
15
+
16
+ def >>(*args)
17
+ FormattingStream[self].>>(*args)
18
+ end
19
+ end
20
+
21
+ # Auxiliar class to implement << & >> operators
22
+ # on Format class and Format instances as a
23
+ # shortcut for the Format#write and #read
24
+ # formatting operators.
25
+ class FormattingStream
26
+ def initialize(format)
27
+ @format = format
28
+ @text = nil
29
+ @type = nil
30
+ @output = []
31
+ end
32
+
33
+ def self.[](*args)
34
+ new *args
35
+ end
36
+
37
+ def to_a
38
+ @output
39
+ end
40
+
41
+ def to_s
42
+ to_a.join
43
+ end
44
+
45
+ def to_str
46
+ to_s
47
+ end
48
+
49
+ def value
50
+ if @output.size > 1
51
+ @output
52
+ else
53
+ @output.first
54
+ end
55
+ end
56
+
57
+ def <<(*objects)
58
+ objects.each do |object|
59
+ case object
60
+ when Format, Hash, Array
61
+ @format.set! object
62
+ when String
63
+ if @type
64
+ @output << @format.read(object, type: @type)
65
+ else
66
+ @output << object
67
+ end
68
+ else
69
+ if @text
70
+ @output << @format.read(@text, type: object)
71
+ elsif object.is_a?(Class)
72
+ @type = object
73
+ else
74
+ @output << @format.write(object)
75
+ end
76
+ end
77
+ end
78
+ self
79
+ end
80
+
81
+ def >>(*objects)
82
+ objects.each do |object|
83
+ case object
84
+ when Format, Hash, Array
85
+ @format.set! object
86
+ when String
87
+ @text = object
88
+ if @type
89
+ @output << @format.read(object, type: @type)
90
+ end
91
+ else
92
+ if @text
93
+ @output << @format.read(@text, type: object)
94
+ elsif object.is_a?(Class)
95
+ @type = object
96
+ else
97
+ @output << @format.write(object)
98
+ end
99
+ end
100
+ end
101
+ self
102
+ end
103
+
104
+ def clear
105
+ @output.clear
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -626,14 +626,23 @@ module Numerals
626
626
 
627
627
  # Expand to the specified number of digits,
628
628
  # then truncate and remove repetitions.
629
- def approximate!(number_of_digits)
630
- expand! number_of_digits
631
- @digits.truncate! number_of_digits
632
- @repeat = nil
629
+ # If no number of digits is given, then it will be
630
+ # converted to approximate numeral only if it is not
631
+ # repeating.
632
+ def approximate!(number_of_digits = nil)
633
+ if number_of_digits.nil?
634
+ if exact? && !repeating?
635
+ @repeat = nil
636
+ end
637
+ else
638
+ expand! number_of_digits
639
+ @digits.truncate! number_of_digits
640
+ @repeat = nil
641
+ end
633
642
  self
634
643
  end
635
644
 
636
- def approximate(number_of_digits)
645
+ def approximate(number_of_digits = nil)
637
646
  dup.approximate! number_of_digits
638
647
  end
639
648
 
@@ -1,3 +1,3 @@
1
1
  module Numerals
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'flt', "~> 1.4.6"
22
- spec.add_dependency 'modalsupport', "~> 0.9.2"
21
+ spec.add_dependency 'flt', "~> 1.4"
22
+ spec.add_dependency 'modalsupport', "~> 0.9"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
25
25
  spec.add_development_dependency "rake"
@@ -38,3 +38,18 @@ PrepareData.init
38
38
  def BigDec(x)
39
39
  BigDecimal.new(x.to_s)
40
40
  end
41
+
42
+
43
+ def assert_same_number(x, y)
44
+ assert_equal x.class, y.class, x.to_s
45
+ case x
46
+ when Flt::Num
47
+ assert_equal x.split, y.split, x.to_s
48
+ when Float
49
+ assert_equal Float.context.split(x), Float.context.split(y), x.to_s
50
+ when Rational
51
+ assert_equal [x.numerator, x.denominator], [y.numerator, y.denominator]
52
+ else
53
+ assert_equal x, y
54
+ end
55
+ end
@@ -0,0 +1,1921 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
+
3
+ require 'numerals'
4
+
5
+ class TestConversions < Test::Unit::TestCase # < Minitest::Test
6
+
7
+ include Numerals
8
+ include Flt
9
+
10
+ def setup
11
+ @dec_context = Flt::DecNum.context
12
+ @bin_context = Flt::BinNum.context
13
+ Flt::DecNum.context = Flt::DecNum::ExtendedContext
14
+ Flt::BinNum.context = Flt::BinNum::ExtendedContext
15
+ end
16
+
17
+ def tear_down
18
+ Flt::DecNum.context = @dec_context
19
+ Flt::BinNum.context = @bin_context
20
+ end
21
+
22
+ def test_special
23
+ assert Conversions.convert(Float::NAN, type: DecNum).nan?
24
+ assert Conversions.convert(Float::NAN, type: DecNum, exact: true).nan?
25
+ assert Conversions.convert(DecNum.context.nan, type: Float).nan?
26
+ assert_equal DecNum.context.infinity, Conversions.convert(Float::INFINITY, type: DecNum)
27
+ assert_equal Float::INFINITY, Conversions.convert(DecNum.context.infinity, type: Float)
28
+ assert_equal -DecNum.context.infinity, Conversions.convert(-Float::INFINITY, type: DecNum)
29
+ assert_equal -Float::INFINITY, Conversions.convert(-DecNum.context.infinity, type: Float)
30
+ end
31
+
32
+ def test_regular
33
+
34
+ x = 0.1
35
+ assert_same_number(
36
+ Float('0X1.999999999999AP-4'), # 0.1
37
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
38
+ )
39
+ assert_same_number(
40
+ Float('0X1.999999999999AP-4'), # 0.1
41
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
42
+ )
43
+ assert_same_number(
44
+ Float('0X1.999999999999AP-4'), # 0.1
45
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
46
+ )
47
+ assert_same_number(
48
+ Float('0X1.999999999999AP-4'), # 0.1
49
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
50
+ )
51
+ assert_same_number(
52
+ Float('0X1.999999999999AP-4'), # 0.1
53
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
54
+ )
55
+ assert_same_number(
56
+ Float('0X1.999999999999AP-4'), # 0.1
57
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
58
+ )
59
+ assert_same_number(
60
+ Float('0X1.999999999999AP-4'), # 0.1
61
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
62
+ )
63
+ assert_same_number(
64
+ Float('0X1.999999999999AP-4'), # 0.1
65
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
66
+ )
67
+ assert_same_number(
68
+ Float('0X1.999999999999AP-4'), # 0.1
69
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
70
+ )
71
+ assert_same_number(
72
+ Float('0X1.999999999999AP-4'), # 0.1
73
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
74
+ )
75
+ assert_same_number(
76
+ Float('0X1.999999999999AP-4'), # 0.1
77
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
78
+ )
79
+ assert_same_number(
80
+ Float('0X1.999999999999AP-4'), # 0.1
81
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
82
+ )
83
+ assert_same_number(
84
+ Float('0X1.999999999999AP-4'), # 0.1
85
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
86
+ )
87
+ assert_same_number(
88
+ Float('0X1.999999999999AP-4'), # 0.1
89
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
90
+ )
91
+ assert_same_number(
92
+ Float('0X1.999999999999AP-4'), # 0.1
93
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
94
+ )
95
+ assert_same_number(
96
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
97
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
98
+ )
99
+ assert_same_number(
100
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
101
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
102
+ )
103
+ assert_same_number(
104
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
105
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
106
+ )
107
+ assert_same_number(
108
+ Flt::BinNum[1, 13421773, -27], # 0.1
109
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
110
+ )
111
+ assert_same_number(
112
+ Flt::BinNum[1, 53687091, -29], # 0.1
113
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
114
+ )
115
+ assert_same_number(
116
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
117
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
118
+ )
119
+ assert_same_number(
120
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
121
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
122
+ )
123
+ assert_same_number(
124
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
125
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
126
+ )
127
+ assert_same_number(
128
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
129
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
130
+ )
131
+ assert_same_number(
132
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
133
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
134
+ )
135
+ assert_same_number(
136
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
137
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
138
+ )
139
+ assert_same_number(
140
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
141
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
142
+ )
143
+ assert_same_number(
144
+ Flt::BinNum[1, 13421773, -27], # 0.1
145
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
146
+ )
147
+ assert_same_number(
148
+ Flt::BinNum[1, 53687091, -29], # 0.1
149
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
150
+ )
151
+ assert_same_number(
152
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
153
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
154
+ )
155
+ assert_same_number(
156
+ DecNum('0.1000000000000000055511151231257827021181583404541015625'),
157
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
158
+ )
159
+ assert_same_number(
160
+ DecNum('0.1000000000000000055511151231257827021181583404541015625'),
161
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
162
+ )
163
+ assert_same_number(
164
+ DecNum('0.100000000'),
165
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
166
+ )
167
+ assert_same_number(
168
+ DecNum('0.1'),
169
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
170
+ )
171
+ assert_same_number(
172
+ DecNum('0.10000000'),
173
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
174
+ )
175
+ assert_same_number(
176
+ DecNum('0.100000000'),
177
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
178
+ )
179
+ assert_same_number(
180
+ DecNum('0.1'),
181
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
182
+ )
183
+ assert_same_number(
184
+ DecNum('0.1'),
185
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
186
+ )
187
+ assert_same_number(
188
+ DecNum('0.100000000'),
189
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
190
+ )
191
+ assert_same_number(
192
+ DecNum('0.10000000000000001'),
193
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
194
+ )
195
+ assert_same_number(
196
+ DecNum('0.10000000000000001'),
197
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
198
+ )
199
+ assert_same_number(
200
+ DecNum('0.100000000'),
201
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
202
+ )
203
+ assert_same_number(
204
+ DecNum('0.1'),
205
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
206
+ )
207
+ assert_same_number(
208
+ DecNum('0.10000000'),
209
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
210
+ )
211
+ assert_same_number(
212
+ DecNum('0.100000000'),
213
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
214
+ )
215
+ assert_same_number(
216
+ Rational(3602879701896397, 36028797018963968),
217
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
218
+ )
219
+ assert_same_number(
220
+ Rational(3602879701896397, 36028797018963968),
221
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
222
+ )
223
+ assert_same_number(
224
+ Rational(3602879701896397, 36028797018963968),
225
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
226
+ )
227
+ assert_same_number(
228
+ Rational(1, 10),
229
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
230
+ )
231
+ assert_same_number(
232
+ Rational(1, 10),
233
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
234
+ )
235
+ assert_same_number(
236
+ Rational(1, 10),
237
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
238
+ )
239
+ assert_same_number(
240
+ Rational(1, 10),
241
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
242
+ )
243
+ assert_same_number(
244
+ Rational(1, 10),
245
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
246
+ )
247
+ assert_same_number(
248
+ Rational(1, 10),
249
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
250
+ )
251
+ assert_same_number(
252
+ Rational(10000000000000001, 100000000000000000),
253
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
254
+ )
255
+ assert_same_number(
256
+ Rational(10000000000000001, 100000000000000000),
257
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
258
+ )
259
+ assert_same_number(
260
+ Rational(10000000000000001, 100000000000000000),
261
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
262
+ )
263
+ assert_same_number(
264
+ Rational(1, 10),
265
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
266
+ )
267
+ assert_same_number(
268
+ Rational(1, 10),
269
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
270
+ )
271
+ assert_same_number(
272
+ Rational(1, 10),
273
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
274
+ )
275
+ x = 0.5
276
+ assert_same_number(
277
+ Float('0X1P-1'), # 0.5
278
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
279
+ )
280
+ assert_same_number(
281
+ Float('0X1P-1'), # 0.5
282
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
283
+ )
284
+ assert_same_number(
285
+ Float('0X1P-1'), # 0.5
286
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
287
+ )
288
+ assert_same_number(
289
+ Float('0X1P-1'), # 0.5
290
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
291
+ )
292
+ assert_same_number(
293
+ Float('0X1P-1'), # 0.5
294
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
295
+ )
296
+ assert_same_number(
297
+ Float('0X1P-1'), # 0.5
298
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
299
+ )
300
+ assert_same_number(
301
+ Float('0X1P-1'), # 0.5
302
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
303
+ )
304
+ assert_same_number(
305
+ Float('0X1P-1'), # 0.5
306
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
307
+ )
308
+ assert_same_number(
309
+ Float('0X1P-1'), # 0.5
310
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
311
+ )
312
+ assert_same_number(
313
+ Float('0X1P-1'), # 0.5
314
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
315
+ )
316
+ assert_same_number(
317
+ Float('0X1P-1'), # 0.5
318
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
319
+ )
320
+ assert_same_number(
321
+ Float('0X1P-1'), # 0.5
322
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
323
+ )
324
+ assert_same_number(
325
+ Float('0X1P-1'), # 0.5
326
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
327
+ )
328
+ assert_same_number(
329
+ Float('0X1P-1'), # 0.5
330
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
331
+ )
332
+ assert_same_number(
333
+ Float('0X1P-1'), # 0.5
334
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
335
+ )
336
+ assert_same_number(
337
+ Flt::BinNum[1, 1, -1], # 0.5
338
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
339
+ )
340
+ assert_same_number(
341
+ Flt::BinNum[1, 1, -1], # 0.5
342
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
343
+ )
344
+ assert_same_number(
345
+ Flt::BinNum[1, 4503599627370496, -53], # 0.5
346
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
347
+ )
348
+ assert_same_number(
349
+ Flt::BinNum[1, 1, -1], # 0.5
350
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
351
+ )
352
+ assert_same_number(
353
+ Flt::BinNum[1, 134217728, -28], # 0.5
354
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
355
+ )
356
+ assert_same_number(
357
+ Flt::BinNum[1, 4503599627370496, -53], # 0.5
358
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
359
+ )
360
+ assert_same_number(
361
+ Flt::BinNum[1, 1, -1], # 0.5
362
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
363
+ )
364
+ assert_same_number(
365
+ Flt::BinNum[1, 1, -1], # 0.5
366
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
367
+ )
368
+ assert_same_number(
369
+ Flt::BinNum[1, 4503599627370496, -53], # 0.5
370
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
371
+ )
372
+ assert_same_number(
373
+ Flt::BinNum[1, 1, -1], # 0.5
374
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
375
+ )
376
+ assert_same_number(
377
+ Flt::BinNum[1, 4503599627370496, -53], # 0.5
378
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
379
+ )
380
+ assert_same_number(
381
+ Flt::BinNum[1, 4503599627370496, -53], # 0.5
382
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
383
+ )
384
+ assert_same_number(
385
+ Flt::BinNum[1, 1, -1], # 0.5
386
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
387
+ )
388
+ assert_same_number(
389
+ Flt::BinNum[1, 134217728, -28], # 0.5
390
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
391
+ )
392
+ assert_same_number(
393
+ Flt::BinNum[1, 4503599627370496, -53], # 0.5
394
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
395
+ )
396
+ assert_same_number(
397
+ DecNum('0.5'),
398
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
399
+ )
400
+ assert_same_number(
401
+ DecNum('0.5'),
402
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
403
+ )
404
+ assert_same_number(
405
+ DecNum('0.500000000'),
406
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
407
+ )
408
+ assert_same_number(
409
+ DecNum('0.5'),
410
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
411
+ )
412
+ assert_same_number(
413
+ DecNum('0.50000000'),
414
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
415
+ )
416
+ assert_same_number(
417
+ DecNum('0.500000000'),
418
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
419
+ )
420
+ assert_same_number(
421
+ DecNum('0.5'),
422
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
423
+ )
424
+ assert_same_number(
425
+ DecNum('0.5'),
426
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
427
+ )
428
+ assert_same_number(
429
+ DecNum('0.500000000'),
430
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
431
+ )
432
+ assert_same_number(
433
+ DecNum('0.5'),
434
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
435
+ )
436
+ assert_same_number(
437
+ DecNum('0.50000000000000000'),
438
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
439
+ )
440
+ assert_same_number(
441
+ DecNum('0.500000000'),
442
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
443
+ )
444
+ assert_same_number(
445
+ DecNum('0.5'),
446
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
447
+ )
448
+ assert_same_number(
449
+ DecNum('0.50000000'),
450
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
451
+ )
452
+ assert_same_number(
453
+ DecNum('0.500000000'),
454
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
455
+ )
456
+ assert_same_number(
457
+ Rational(1, 2),
458
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
459
+ )
460
+ assert_same_number(
461
+ Rational(1, 2),
462
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
463
+ )
464
+ assert_same_number(
465
+ Rational(1, 2),
466
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
467
+ )
468
+ assert_same_number(
469
+ Rational(1, 2),
470
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
471
+ )
472
+ assert_same_number(
473
+ Rational(1, 2),
474
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
475
+ )
476
+ assert_same_number(
477
+ Rational(1, 2),
478
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
479
+ )
480
+ assert_same_number(
481
+ Rational(1, 2),
482
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
483
+ )
484
+ assert_same_number(
485
+ Rational(1, 2),
486
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
487
+ )
488
+ assert_same_number(
489
+ Rational(1, 2),
490
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
491
+ )
492
+ assert_same_number(
493
+ Rational(1, 2),
494
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
495
+ )
496
+ assert_same_number(
497
+ Rational(1, 2),
498
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
499
+ )
500
+ assert_same_number(
501
+ Rational(1, 2),
502
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
503
+ )
504
+ assert_same_number(
505
+ Rational(1, 2),
506
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
507
+ )
508
+ assert_same_number(
509
+ Rational(1, 2),
510
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
511
+ )
512
+ assert_same_number(
513
+ Rational(1, 2),
514
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
515
+ )
516
+ x = Flt::BinNum('0.1', :fixed)
517
+ assert_same_number(
518
+ Float('0X1.999999999999AP-4'), # 0.1
519
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
520
+ )
521
+ assert_same_number(
522
+ Float('0X1.999999999999AP-4'), # 0.1
523
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
524
+ )
525
+ assert_same_number(
526
+ Float('0X1.999999999999AP-4'), # 0.1
527
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
528
+ )
529
+ assert_same_number(
530
+ Float('0X1.999999999999AP-4'), # 0.1
531
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
532
+ )
533
+ assert_same_number(
534
+ Float('0X1.999999999999AP-4'), # 0.1
535
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
536
+ )
537
+ assert_same_number(
538
+ Float('0X1.999999999999AP-4'), # 0.1
539
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
540
+ )
541
+ assert_same_number(
542
+ Float('0X1.999999999999AP-4'), # 0.1
543
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
544
+ )
545
+ assert_same_number(
546
+ Float('0X1.999999999999AP-4'), # 0.1
547
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
548
+ )
549
+ assert_same_number(
550
+ Float('0X1.999999999999AP-4'), # 0.1
551
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
552
+ )
553
+ assert_same_number(
554
+ Float('0X1.999999999999AP-4'), # 0.1
555
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
556
+ )
557
+ assert_same_number(
558
+ Float('0X1.999999999999AP-4'), # 0.1
559
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
560
+ )
561
+ assert_same_number(
562
+ Float('0X1.999999999999AP-4'), # 0.1
563
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
564
+ )
565
+ assert_same_number(
566
+ Float('0X1.999999999999AP-4'), # 0.1
567
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
568
+ )
569
+ assert_same_number(
570
+ Float('0X1.999999999999AP-4'), # 0.1
571
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
572
+ )
573
+ assert_same_number(
574
+ Float('0X1.999999999999AP-4'), # 0.1
575
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
576
+ )
577
+ assert_same_number(
578
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
579
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
580
+ )
581
+ assert_same_number(
582
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
583
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
584
+ )
585
+ assert_same_number(
586
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
587
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
588
+ )
589
+ assert_same_number(
590
+ Flt::BinNum[1, 13421773, -27], # 0.1
591
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
592
+ )
593
+ assert_same_number(
594
+ Flt::BinNum[1, 53687091, -29], # 0.1
595
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
596
+ )
597
+ assert_same_number(
598
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
599
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
600
+ )
601
+ assert_same_number(
602
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
603
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
604
+ )
605
+ assert_same_number(
606
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
607
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
608
+ )
609
+ assert_same_number(
610
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
611
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
612
+ )
613
+ assert_same_number(
614
+ Flt::BinNum[1, 3602879701896397, -55], # 0.1
615
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
616
+ )
617
+ assert_same_number(
618
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
619
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
620
+ )
621
+ assert_same_number(
622
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
623
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
624
+ )
625
+ assert_same_number(
626
+ Flt::BinNum[1, 13421773, -27], # 0.1
627
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
628
+ )
629
+ assert_same_number(
630
+ Flt::BinNum[1, 53687091, -29], # 0.1
631
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
632
+ )
633
+ assert_same_number(
634
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
635
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
636
+ )
637
+ assert_same_number(
638
+ DecNum('0.1000000000000000055511151231257827021181583404541015625'),
639
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
640
+ )
641
+ assert_same_number(
642
+ DecNum('0.1000000000000000055511151231257827021181583404541015625'),
643
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
644
+ )
645
+ assert_same_number(
646
+ DecNum('0.100000000'),
647
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
648
+ )
649
+ assert_same_number(
650
+ DecNum('0.1'),
651
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
652
+ )
653
+ assert_same_number(
654
+ DecNum('0.10000000'),
655
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
656
+ )
657
+ assert_same_number(
658
+ DecNum('0.100000000'),
659
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
660
+ )
661
+ assert_same_number(
662
+ DecNum('0.1'),
663
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
664
+ )
665
+ assert_same_number(
666
+ DecNum('0.1'),
667
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
668
+ )
669
+ assert_same_number(
670
+ DecNum('0.100000000'),
671
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
672
+ )
673
+ assert_same_number(
674
+ DecNum('0.10000000000000001'),
675
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
676
+ )
677
+ assert_same_number(
678
+ DecNum('0.10000000000000001'),
679
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
680
+ )
681
+ assert_same_number(
682
+ DecNum('0.100000000'),
683
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
684
+ )
685
+ assert_same_number(
686
+ DecNum('0.1'),
687
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
688
+ )
689
+ assert_same_number(
690
+ DecNum('0.10000000'),
691
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
692
+ )
693
+ assert_same_number(
694
+ DecNum('0.100000000'),
695
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
696
+ )
697
+ assert_same_number(
698
+ Rational(3602879701896397, 36028797018963968),
699
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
700
+ )
701
+ assert_same_number(
702
+ Rational(3602879701896397, 36028797018963968),
703
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
704
+ )
705
+ assert_same_number(
706
+ Rational(3602879701896397, 36028797018963968),
707
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
708
+ )
709
+ assert_same_number(
710
+ Rational(1, 10),
711
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
712
+ )
713
+ assert_same_number(
714
+ Rational(1, 10),
715
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
716
+ )
717
+ assert_same_number(
718
+ Rational(1, 10),
719
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
720
+ )
721
+ assert_same_number(
722
+ Rational(1, 10),
723
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
724
+ )
725
+ assert_same_number(
726
+ Rational(1, 10),
727
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
728
+ )
729
+ assert_same_number(
730
+ Rational(1, 10),
731
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
732
+ )
733
+ assert_same_number(
734
+ Rational(10000000000000001, 100000000000000000),
735
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
736
+ )
737
+ assert_same_number(
738
+ Rational(10000000000000001, 100000000000000000),
739
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
740
+ )
741
+ assert_same_number(
742
+ Rational(10000000000000001, 100000000000000000),
743
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
744
+ )
745
+ assert_same_number(
746
+ Rational(1, 10),
747
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
748
+ )
749
+ assert_same_number(
750
+ Rational(1, 10),
751
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
752
+ )
753
+ assert_same_number(
754
+ Rational(1, 10),
755
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
756
+ )
757
+ x = Flt::BinNum('0.1', :free)
758
+ assert_same_number(
759
+ Float('0X1.AP-4'), # 0.1015625
760
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
761
+ )
762
+ assert_same_number(
763
+ Float('0X1.AP-4'), # 0.1015625
764
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
765
+ )
766
+ assert_same_number(
767
+ Float('0X1.AP-4'), # 0.1015625
768
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
769
+ )
770
+ assert_same_number(
771
+ Float('0X1.AP-4'), # 0.1015625
772
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
773
+ )
774
+ assert_same_number(
775
+ Float('0X1.AP-4'), # 0.1015625
776
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
777
+ )
778
+ assert_same_number(
779
+ Float('0X1.AP-4'), # 0.1015625
780
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
781
+ )
782
+ assert_same_number(
783
+ Float('0X1.AP-4'), # 0.1015625
784
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
785
+ )
786
+ assert_same_number(
787
+ Float('0X1.AP-4'), # 0.1015625
788
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
789
+ )
790
+ assert_same_number(
791
+ Float('0X1.AP-4'), # 0.1015625
792
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
793
+ )
794
+ assert_same_number(
795
+ Float('0X1.AP-4'), # 0.1015625
796
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
797
+ )
798
+ assert_same_number(
799
+ Float('0X1.AP-4'), # 0.1015625
800
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
801
+ )
802
+ assert_same_number(
803
+ Float('0X1.AP-4'), # 0.1015625
804
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
805
+ )
806
+ assert_same_number(
807
+ Float('0X1.A1CAC083126E9P-4'), # 0.102
808
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
809
+ )
810
+ assert_same_number(
811
+ Float('0X1.A1CAC083126E9P-4'), # 0.102
812
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
813
+ )
814
+ assert_same_number(
815
+ Float('0X1.A1CAC083126E9P-4'), # 0.102
816
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
817
+ )
818
+ assert_same_number(
819
+ Flt::BinNum[1, 13, -7], # 0.1
820
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
821
+ )
822
+ assert_same_number(
823
+ Flt::BinNum[1, 13, -7], # 0.1
824
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
825
+ )
826
+ assert_same_number(
827
+ Flt::BinNum[1, 7318349394477056, -56], # 0.1015625
828
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
829
+ )
830
+ assert_same_number(
831
+ Flt::BinNum[1, 13, -7], # 0.1
832
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
833
+ )
834
+ assert_same_number(
835
+ Flt::BinNum[1, 27262976, -28], # 0.1015625
836
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
837
+ )
838
+ assert_same_number(
839
+ Flt::BinNum[1, 7318349394477056, -56], # 0.1015625
840
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
841
+ )
842
+ assert_same_number(
843
+ Flt::BinNum[1, 13, -7], # 0.1
844
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
845
+ )
846
+ assert_same_number(
847
+ Flt::BinNum[1, 13, -7], # 0.1
848
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
849
+ )
850
+ assert_same_number(
851
+ Flt::BinNum[1, 7318349394477056, -56], # 0.1015625
852
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
853
+ )
854
+ assert_same_number(
855
+ Flt::BinNum[1, 13, -7], # 0.1
856
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
857
+ )
858
+ assert_same_number(
859
+ Flt::BinNum[1, 26, -8], # 0.1
860
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
861
+ )
862
+ assert_same_number(
863
+ Flt::BinNum[1, 7318349394477056, -56], # 0.1015625
864
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
865
+ )
866
+ assert_same_number(
867
+ Flt::BinNum[1, 13, -7], # 0.1
868
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
869
+ )
870
+ assert_same_number(
871
+ Flt::BinNum[1, 209, -11], # 0.102
872
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
873
+ )
874
+ assert_same_number(
875
+ Flt::BinNum[1, 7349874591868649, -56], # 0.102
876
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
877
+ )
878
+ assert_same_number(
879
+ DecNum('0.1015625'),
880
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
881
+ )
882
+ assert_same_number(
883
+ DecNum('0.1015625'),
884
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
885
+ )
886
+ assert_same_number(
887
+ DecNum('0.101562500'),
888
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
889
+ )
890
+ assert_same_number(
891
+ DecNum('0.1015625'),
892
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
893
+ )
894
+ assert_same_number(
895
+ DecNum('0.10156250'),
896
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
897
+ )
898
+ assert_same_number(
899
+ DecNum('0.101562500'),
900
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
901
+ )
902
+ assert_same_number(
903
+ DecNum('0.1'),
904
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
905
+ )
906
+ assert_same_number(
907
+ DecNum('0.1'),
908
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
909
+ )
910
+ assert_same_number(
911
+ DecNum('0.100000000'),
912
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
913
+ )
914
+ assert_same_number(
915
+ DecNum('0.102'),
916
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
917
+ )
918
+ assert_same_number(
919
+ DecNum('0.102'),
920
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
921
+ )
922
+ assert_same_number(
923
+ DecNum('0.102000000'),
924
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
925
+ )
926
+ assert_same_number(
927
+ DecNum('0.102'),
928
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
929
+ )
930
+ assert_same_number(
931
+ DecNum('0.102'),
932
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
933
+ )
934
+ assert_same_number(
935
+ DecNum('0.102000000'),
936
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
937
+ )
938
+ assert_same_number(
939
+ Rational(13, 128),
940
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
941
+ )
942
+ assert_same_number(
943
+ Rational(13, 128),
944
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
945
+ )
946
+ assert_same_number(
947
+ Rational(13, 128),
948
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
949
+ )
950
+ assert_same_number(
951
+ Rational(13, 128),
952
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
953
+ )
954
+ assert_same_number(
955
+ Rational(13, 128),
956
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
957
+ )
958
+ assert_same_number(
959
+ Rational(13, 128),
960
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
961
+ )
962
+ assert_same_number(
963
+ Rational(1, 10),
964
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
965
+ )
966
+ assert_same_number(
967
+ Rational(1, 10),
968
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
969
+ )
970
+ assert_same_number(
971
+ Rational(1, 10),
972
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
973
+ )
974
+ assert_same_number(
975
+ Rational(51, 500),
976
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
977
+ )
978
+ assert_same_number(
979
+ Rational(51, 500),
980
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
981
+ )
982
+ assert_same_number(
983
+ Rational(51, 500),
984
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
985
+ )
986
+ assert_same_number(
987
+ Rational(51, 500),
988
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
989
+ )
990
+ assert_same_number(
991
+ Rational(51, 500),
992
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
993
+ )
994
+ assert_same_number(
995
+ Rational(51, 500),
996
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
997
+ )
998
+ x = Flt::DecNum('0.1')
999
+ assert_same_number(
1000
+ Float('0X1.999999999999AP-4'), # 0.1
1001
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
1002
+ )
1003
+ assert_same_number(
1004
+ Float('0X1.999999999999AP-4'), # 0.1
1005
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
1006
+ )
1007
+ assert_same_number(
1008
+ Float('0X1.999999999999AP-4'), # 0.1
1009
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
1010
+ )
1011
+ assert_same_number(
1012
+ Float('0X1.999999999999AP-4'), # 0.1
1013
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
1014
+ )
1015
+ assert_same_number(
1016
+ Float('0X1.999999999999AP-4'), # 0.1
1017
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
1018
+ )
1019
+ assert_same_number(
1020
+ Float('0X1.999999999999AP-4'), # 0.1
1021
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
1022
+ )
1023
+ assert_same_number(
1024
+ Float('0X1P-3'), # 0.125
1025
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
1026
+ )
1027
+ assert_same_number(
1028
+ Float('0X1P-3'), # 0.125
1029
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
1030
+ )
1031
+ assert_same_number(
1032
+ Float('0X1P-3'), # 0.125
1033
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
1034
+ )
1035
+ assert_same_number(
1036
+ Float('0X1.AP-4'), # 0.1015625
1037
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
1038
+ )
1039
+ assert_same_number(
1040
+ Float('0X1.AP-4'), # 0.1015625
1041
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
1042
+ )
1043
+ assert_same_number(
1044
+ Float('0X1.AP-4'), # 0.1015625
1045
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
1046
+ )
1047
+ assert_same_number(
1048
+ Float('0X1.999999999999AP-4'), # 0.1
1049
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
1050
+ )
1051
+ assert_same_number(
1052
+ Float('0X1.999999999999AP-4'), # 0.1
1053
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
1054
+ )
1055
+ assert_same_number(
1056
+ Float('0X1.999999999999AP-4'), # 0.1
1057
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
1058
+ )
1059
+ assert_same_number(
1060
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1061
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1062
+ )
1063
+ assert_same_number(
1064
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1065
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1066
+ )
1067
+ assert_same_number(
1068
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1069
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1070
+ )
1071
+ assert_same_number(
1072
+ Flt::BinNum[1, 13421773, -27], # 0.1
1073
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1074
+ )
1075
+ assert_same_number(
1076
+ Flt::BinNum[1, 53687091, -29], # 0.1
1077
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1078
+ )
1079
+ assert_same_number(
1080
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1081
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1082
+ )
1083
+ assert_same_number(
1084
+ Flt::BinNum[1, 1, -3], # 0.1
1085
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
1086
+ )
1087
+ assert_same_number(
1088
+ Flt::BinNum[1, 1, -3], # 0.1
1089
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
1090
+ )
1091
+ assert_same_number(
1092
+ Flt::BinNum[1, 4503599627370496, -55], # 0.125
1093
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
1094
+ )
1095
+ assert_same_number(
1096
+ Flt::BinNum[1, 13, -7], # 0.1
1097
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1098
+ )
1099
+ assert_same_number(
1100
+ Flt::BinNum[1, 26, -8], # 0.1
1101
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1102
+ )
1103
+ assert_same_number(
1104
+ Flt::BinNum[1, 7318349394477056, -56], # 0.1015625
1105
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1106
+ )
1107
+ assert_same_number(
1108
+ Flt::BinNum[1, 13, -7], # 0.1
1109
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1110
+ )
1111
+ assert_same_number(
1112
+ Flt::BinNum[1, 51, -9], # 0.1
1113
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1114
+ )
1115
+ assert_same_number(
1116
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1117
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1118
+ )
1119
+ assert_same_number(
1120
+ DecNum('0.1'),
1121
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1122
+ )
1123
+ assert_same_number(
1124
+ DecNum('0.1'),
1125
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1126
+ )
1127
+ assert_same_number(
1128
+ DecNum('0.100000000'),
1129
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1130
+ )
1131
+ assert_same_number(
1132
+ DecNum('0.1'),
1133
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1134
+ )
1135
+ assert_same_number(
1136
+ DecNum('0.10000000'),
1137
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1138
+ )
1139
+ assert_same_number(
1140
+ DecNum('0.100000000'),
1141
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1142
+ )
1143
+ assert_same_number(
1144
+ DecNum('0.1'),
1145
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
1146
+ )
1147
+ assert_same_number(
1148
+ DecNum('0.1'),
1149
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
1150
+ )
1151
+ assert_same_number(
1152
+ DecNum('0.100000000'),
1153
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
1154
+ )
1155
+ assert_same_number(
1156
+ DecNum('0.1'),
1157
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1158
+ )
1159
+ assert_same_number(
1160
+ DecNum('0.1'),
1161
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1162
+ )
1163
+ assert_same_number(
1164
+ DecNum('0.100000000'),
1165
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1166
+ )
1167
+ assert_same_number(
1168
+ DecNum('0.1'),
1169
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1170
+ )
1171
+ assert_same_number(
1172
+ DecNum('0.10'),
1173
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1174
+ )
1175
+ assert_same_number(
1176
+ DecNum('0.100000000'),
1177
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1178
+ )
1179
+ assert_same_number(
1180
+ Rational(1, 10),
1181
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
1182
+ )
1183
+ assert_same_number(
1184
+ Rational(1, 10),
1185
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
1186
+ )
1187
+ assert_same_number(
1188
+ Rational(1, 10),
1189
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
1190
+ )
1191
+ assert_same_number(
1192
+ Rational(1, 10),
1193
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
1194
+ )
1195
+ assert_same_number(
1196
+ Rational(1, 10),
1197
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
1198
+ )
1199
+ assert_same_number(
1200
+ Rational(1, 10),
1201
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1202
+ )
1203
+ assert_same_number(
1204
+ Rational(1, 10),
1205
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
1206
+ )
1207
+ assert_same_number(
1208
+ Rational(1, 10),
1209
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
1210
+ )
1211
+ assert_same_number(
1212
+ Rational(1, 10),
1213
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
1214
+ )
1215
+ assert_same_number(
1216
+ Rational(1, 10),
1217
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
1218
+ )
1219
+ assert_same_number(
1220
+ Rational(1, 10),
1221
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
1222
+ )
1223
+ assert_same_number(
1224
+ Rational(1, 10),
1225
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
1226
+ )
1227
+ assert_same_number(
1228
+ Rational(1, 10),
1229
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
1230
+ )
1231
+ assert_same_number(
1232
+ Rational(1, 10),
1233
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
1234
+ )
1235
+ assert_same_number(
1236
+ Rational(1, 10),
1237
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1238
+ )
1239
+ x = Flt::DecNum('0.1000')
1240
+ assert_same_number(
1241
+ Float('0X1.999999999999AP-4'), # 0.1
1242
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
1243
+ )
1244
+ assert_same_number(
1245
+ Float('0X1.999999999999AP-4'), # 0.1
1246
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
1247
+ )
1248
+ assert_same_number(
1249
+ Float('0X1.999999999999AP-4'), # 0.1
1250
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
1251
+ )
1252
+ assert_same_number(
1253
+ Float('0X1.999999999999AP-4'), # 0.1
1254
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
1255
+ )
1256
+ assert_same_number(
1257
+ Float('0X1.999999999999AP-4'), # 0.1
1258
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
1259
+ )
1260
+ assert_same_number(
1261
+ Float('0X1.999999999999AP-4'), # 0.1
1262
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
1263
+ )
1264
+ assert_same_number(
1265
+ Float('0X1.99CP-4'), # 0.10003662109375
1266
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
1267
+ )
1268
+ assert_same_number(
1269
+ Float('0X1.99CP-4'), # 0.10003662109375
1270
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
1271
+ )
1272
+ assert_same_number(
1273
+ Float('0X1.99CP-4'), # 0.10003662109375
1274
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
1275
+ )
1276
+ assert_same_number(
1277
+ Float('0X1.9998P-4'), # 0.09999847412109375
1278
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
1279
+ )
1280
+ assert_same_number(
1281
+ Float('0X1.9998P-4'), # 0.09999847412109375
1282
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
1283
+ )
1284
+ assert_same_number(
1285
+ Float('0X1.9998P-4'), # 0.09999847412109375
1286
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
1287
+ )
1288
+ assert_same_number(
1289
+ Float('0X1.999999999999AP-4'), # 0.1
1290
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
1291
+ )
1292
+ assert_same_number(
1293
+ Float('0X1.999999999999AP-4'), # 0.1
1294
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
1295
+ )
1296
+ assert_same_number(
1297
+ Float('0X1.999999999999AP-4'), # 0.1
1298
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
1299
+ )
1300
+ assert_same_number(
1301
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1302
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1303
+ )
1304
+ assert_same_number(
1305
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1306
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1307
+ )
1308
+ assert_same_number(
1309
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1310
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1311
+ )
1312
+ assert_same_number(
1313
+ Flt::BinNum[1, 13421773, -27], # 0.1
1314
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1315
+ )
1316
+ assert_same_number(
1317
+ Flt::BinNum[1, 53687091, -29], # 0.1
1318
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1319
+ )
1320
+ assert_same_number(
1321
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1322
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1323
+ )
1324
+ assert_same_number(
1325
+ Flt::BinNum[1, 1639, -14], # 0.10004
1326
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
1327
+ )
1328
+ assert_same_number(
1329
+ Flt::BinNum[1, 1639, -14], # 0.10004
1330
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
1331
+ )
1332
+ assert_same_number(
1333
+ Flt::BinNum[1, 7208398231699456, -56], # 0.10003662109375
1334
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
1335
+ )
1336
+ assert_same_number(
1337
+ Flt::BinNum[1, 13107, -17], # 0.1
1338
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1339
+ )
1340
+ assert_same_number(
1341
+ Flt::BinNum[1, 13107, -17], # 0.1
1342
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1343
+ )
1344
+ assert_same_number(
1345
+ Flt::BinNum[1, 7205649452630016, -56], # 0.09999847412109375
1346
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1347
+ )
1348
+ assert_same_number(
1349
+ Flt::BinNum[1, 26215, -18], # 0.100002
1350
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1351
+ )
1352
+ assert_same_number(
1353
+ Flt::BinNum[1, 209715, -21], # 0.1
1354
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1355
+ )
1356
+ assert_same_number(
1357
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1358
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1359
+ )
1360
+ assert_same_number(
1361
+ DecNum('0.1'),
1362
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1363
+ )
1364
+ assert_same_number(
1365
+ DecNum('0.1'),
1366
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1367
+ )
1368
+ assert_same_number(
1369
+ DecNum('0.100000000'),
1370
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1371
+ )
1372
+ assert_same_number(
1373
+ DecNum('0.1'),
1374
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1375
+ )
1376
+ assert_same_number(
1377
+ DecNum('0.10000000'),
1378
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1379
+ )
1380
+ assert_same_number(
1381
+ DecNum('0.100000000'),
1382
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1383
+ )
1384
+ assert_same_number(
1385
+ DecNum('0.1'),
1386
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
1387
+ )
1388
+ assert_same_number(
1389
+ DecNum('0.1'),
1390
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
1391
+ )
1392
+ assert_same_number(
1393
+ DecNum('0.100000000'),
1394
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
1395
+ )
1396
+ assert_same_number(
1397
+ DecNum('0.1'),
1398
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1399
+ )
1400
+ assert_same_number(
1401
+ DecNum('0.1000'),
1402
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1403
+ )
1404
+ assert_same_number(
1405
+ DecNum('0.100000000'),
1406
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1407
+ )
1408
+ assert_same_number(
1409
+ DecNum('0.1'),
1410
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1411
+ )
1412
+ assert_same_number(
1413
+ DecNum('0.10000'),
1414
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1415
+ )
1416
+ assert_same_number(
1417
+ DecNum('0.100000000'),
1418
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1419
+ )
1420
+ assert_same_number(
1421
+ Rational(1, 10),
1422
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
1423
+ )
1424
+ assert_same_number(
1425
+ Rational(1, 10),
1426
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
1427
+ )
1428
+ assert_same_number(
1429
+ Rational(1, 10),
1430
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
1431
+ )
1432
+ assert_same_number(
1433
+ Rational(1, 10),
1434
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
1435
+ )
1436
+ assert_same_number(
1437
+ Rational(1, 10),
1438
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
1439
+ )
1440
+ assert_same_number(
1441
+ Rational(1, 10),
1442
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1443
+ )
1444
+ assert_same_number(
1445
+ Rational(1, 10),
1446
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
1447
+ )
1448
+ assert_same_number(
1449
+ Rational(1, 10),
1450
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
1451
+ )
1452
+ assert_same_number(
1453
+ Rational(1, 10),
1454
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
1455
+ )
1456
+ assert_same_number(
1457
+ Rational(1, 10),
1458
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
1459
+ )
1460
+ assert_same_number(
1461
+ Rational(1, 10),
1462
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
1463
+ )
1464
+ assert_same_number(
1465
+ Rational(1, 10),
1466
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
1467
+ )
1468
+ assert_same_number(
1469
+ Rational(1, 10),
1470
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
1471
+ )
1472
+ assert_same_number(
1473
+ Rational(1, 10),
1474
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
1475
+ )
1476
+ assert_same_number(
1477
+ Rational(1, 10),
1478
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1479
+ )
1480
+ x = Flt::DecNum('0.1000', :fixed)
1481
+ assert_same_number(
1482
+ Float('0X1.999999999999AP-4'), # 0.1
1483
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
1484
+ )
1485
+ assert_same_number(
1486
+ Float('0X1.999999999999AP-4'), # 0.1
1487
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
1488
+ )
1489
+ assert_same_number(
1490
+ Float('0X1.999999999999AP-4'), # 0.1
1491
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
1492
+ )
1493
+ assert_same_number(
1494
+ Float('0X1.999999999999AP-4'), # 0.1
1495
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
1496
+ )
1497
+ assert_same_number(
1498
+ Float('0X1.999999999999AP-4'), # 0.1
1499
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
1500
+ )
1501
+ assert_same_number(
1502
+ Float('0X1.999999999999AP-4'), # 0.1
1503
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
1504
+ )
1505
+ assert_same_number(
1506
+ Float('0X1.999999AP-4'), # 0.10000000009313226
1507
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Float)
1508
+ )
1509
+ assert_same_number(
1510
+ Float('0X1.999999AP-4'), # 0.10000000009313226
1511
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Float)
1512
+ )
1513
+ assert_same_number(
1514
+ Float('0X1.999999AP-4'), # 0.10000000009313226
1515
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Float)
1516
+ )
1517
+ assert_same_number(
1518
+ Float('0X1.99999998P-4'), # 0.09999999997671694
1519
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Float)
1520
+ )
1521
+ assert_same_number(
1522
+ Float('0X1.99999998P-4'), # 0.09999999997671694
1523
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Float)
1524
+ )
1525
+ assert_same_number(
1526
+ Float('0X1.99999998P-4'), # 0.09999999997671694
1527
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Float)
1528
+ )
1529
+ assert_same_number(
1530
+ Float('0X1.999999999999AP-4'), # 0.1
1531
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Float)
1532
+ )
1533
+ assert_same_number(
1534
+ Float('0X1.999999999999AP-4'), # 0.1
1535
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Float)
1536
+ )
1537
+ assert_same_number(
1538
+ Float('0X1.999999999999AP-4'), # 0.1
1539
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Float)
1540
+ )
1541
+ assert_same_number(
1542
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1543
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1544
+ )
1545
+ assert_same_number(
1546
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1547
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1548
+ )
1549
+ assert_same_number(
1550
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1551
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1552
+ )
1553
+ assert_same_number(
1554
+ Flt::BinNum[1, 13421773, -27], # 0.1
1555
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1556
+ )
1557
+ assert_same_number(
1558
+ Flt::BinNum[1, 53687091, -29], # 0.1
1559
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1560
+ )
1561
+ assert_same_number(
1562
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1563
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1564
+ )
1565
+ assert_same_number(
1566
+ Flt::BinNum[1, 214748365, -31], # 0.1
1567
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::BinNum)
1568
+ )
1569
+ assert_same_number(
1570
+ Flt::BinNum[1, 214748365, -31], # 0.1
1571
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::BinNum)
1572
+ )
1573
+ assert_same_number(
1574
+ Flt::BinNum[1, 7205759410503680, -56], # 0.10000000009313226
1575
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::BinNum)
1576
+ )
1577
+ assert_same_number(
1578
+ Flt::BinNum[1, 858993459, -33], # 0.1
1579
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1580
+ )
1581
+ assert_same_number(
1582
+ Flt::BinNum[1, 858993459, -33], # 0.1
1583
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1584
+ )
1585
+ assert_same_number(
1586
+ Flt::BinNum[1, 7205759402115072, -56], # 0.09999999997671694
1587
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1588
+ )
1589
+ assert_same_number(
1590
+ Flt::BinNum[1, 13421773, -27], # 0.1
1591
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1592
+ )
1593
+ assert_same_number(
1594
+ Flt::BinNum[1, 53687091, -29], # 0.1
1595
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1596
+ )
1597
+ assert_same_number(
1598
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1599
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1600
+ )
1601
+ assert_same_number(
1602
+ DecNum('0.1'),
1603
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1604
+ )
1605
+ assert_same_number(
1606
+ DecNum('0.1'),
1607
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1608
+ )
1609
+ assert_same_number(
1610
+ DecNum('0.100000000'),
1611
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1612
+ )
1613
+ assert_same_number(
1614
+ DecNum('0.1'),
1615
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1616
+ )
1617
+ assert_same_number(
1618
+ DecNum('0.10000000'),
1619
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1620
+ )
1621
+ assert_same_number(
1622
+ DecNum('0.100000000'),
1623
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1624
+ )
1625
+ assert_same_number(
1626
+ DecNum('0.1'),
1627
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Flt::DecNum)
1628
+ )
1629
+ assert_same_number(
1630
+ DecNum('0.1'),
1631
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Flt::DecNum)
1632
+ )
1633
+ assert_same_number(
1634
+ DecNum('0.100000000'),
1635
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Flt::DecNum)
1636
+ )
1637
+ assert_same_number(
1638
+ DecNum('0.1'),
1639
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1640
+ )
1641
+ assert_same_number(
1642
+ DecNum('0.100000000'),
1643
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1644
+ )
1645
+ assert_same_number(
1646
+ DecNum('0.100000000'),
1647
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1648
+ )
1649
+ assert_same_number(
1650
+ DecNum('0.1'),
1651
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1652
+ )
1653
+ assert_same_number(
1654
+ DecNum('0.10000000'),
1655
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1656
+ )
1657
+ assert_same_number(
1658
+ DecNum('0.100000000'),
1659
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1660
+ )
1661
+ assert_same_number(
1662
+ Rational(1, 10),
1663
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
1664
+ )
1665
+ assert_same_number(
1666
+ Rational(1, 10),
1667
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
1668
+ )
1669
+ assert_same_number(
1670
+ Rational(1, 10),
1671
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
1672
+ )
1673
+ assert_same_number(
1674
+ Rational(1, 10),
1675
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
1676
+ )
1677
+ assert_same_number(
1678
+ Rational(1, 10),
1679
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
1680
+ )
1681
+ assert_same_number(
1682
+ Rational(1, 10),
1683
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1684
+ )
1685
+ assert_same_number(
1686
+ Rational(1, 10),
1687
+ Conversions.convert(x, rounding:[:short], output_mode: :short, type: Rational)
1688
+ )
1689
+ assert_same_number(
1690
+ Rational(1, 10),
1691
+ Conversions.convert(x, rounding:[:short], output_mode: :free, type: Rational)
1692
+ )
1693
+ assert_same_number(
1694
+ Rational(1, 10),
1695
+ Conversions.convert(x, rounding:[:short], output_mode: :fixed, type: Rational)
1696
+ )
1697
+ assert_same_number(
1698
+ Rational(1, 10),
1699
+ Conversions.convert(x, rounding:[:free], output_mode: :short, type: Rational)
1700
+ )
1701
+ assert_same_number(
1702
+ Rational(1, 10),
1703
+ Conversions.convert(x, rounding:[:free], output_mode: :free, type: Rational)
1704
+ )
1705
+ assert_same_number(
1706
+ Rational(1, 10),
1707
+ Conversions.convert(x, rounding:[:free], output_mode: :fixed, type: Rational)
1708
+ )
1709
+ assert_same_number(
1710
+ Rational(1, 10),
1711
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :short, type: Rational)
1712
+ )
1713
+ assert_same_number(
1714
+ Rational(1, 10),
1715
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :free, type: Rational)
1716
+ )
1717
+ assert_same_number(
1718
+ Rational(1, 10),
1719
+ Conversions.convert(x, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1720
+ )
1721
+ x = Rational(1,10)
1722
+ assert_same_number(
1723
+ Float('0X1.999999999999AP-4'), # 0.1
1724
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
1725
+ )
1726
+ assert_same_number(
1727
+ Float('0X1.999999999999AP-4'), # 0.1
1728
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
1729
+ )
1730
+ assert_same_number(
1731
+ Float('0X1.999999999999AP-4'), # 0.1
1732
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
1733
+ )
1734
+ assert_same_number(
1735
+ Float('0X1.999999999999AP-4'), # 0.1
1736
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
1737
+ )
1738
+ assert_same_number(
1739
+ Float('0X1.999999999999AP-4'), # 0.1
1740
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
1741
+ )
1742
+ assert_same_number(
1743
+ Float('0X1.999999999999AP-4'), # 0.1
1744
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
1745
+ )
1746
+ assert_same_number(
1747
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1748
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1749
+ )
1750
+ assert_same_number(
1751
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1752
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1753
+ )
1754
+ assert_same_number(
1755
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1756
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1757
+ )
1758
+ assert_same_number(
1759
+ Flt::BinNum[1, 13421773, -27], # 0.1
1760
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1761
+ )
1762
+ assert_same_number(
1763
+ Flt::BinNum[1, 53687091, -29], # 0.1
1764
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1765
+ )
1766
+ assert_same_number(
1767
+ Flt::BinNum[1, 7205759403792794, -56], # 0.1
1768
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1769
+ )
1770
+ assert_same_number(
1771
+ DecNum('0.1'),
1772
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1773
+ )
1774
+ assert_same_number(
1775
+ DecNum('0.1'),
1776
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1777
+ )
1778
+ assert_same_number(
1779
+ DecNum('0.100000000'),
1780
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1781
+ )
1782
+ assert_same_number(
1783
+ DecNum('0.1'),
1784
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1785
+ )
1786
+ assert_same_number(
1787
+ DecNum('0.10000000'),
1788
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1789
+ )
1790
+ assert_same_number(
1791
+ DecNum('0.100000000'),
1792
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1793
+ )
1794
+ assert_same_number(
1795
+ Rational(1, 10),
1796
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
1797
+ )
1798
+ assert_same_number(
1799
+ Rational(1, 10),
1800
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
1801
+ )
1802
+ assert_same_number(
1803
+ Rational(1, 10),
1804
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
1805
+ )
1806
+ assert_same_number(
1807
+ Rational(1, 10),
1808
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
1809
+ )
1810
+ assert_same_number(
1811
+ Rational(1, 10),
1812
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
1813
+ )
1814
+ assert_same_number(
1815
+ Rational(1, 10),
1816
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1817
+ )
1818
+ x = Rational(1,3)
1819
+ assert_same_number(
1820
+ Float('0X1.5555555555555P-2'), # 0.3333333333333333
1821
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Float)
1822
+ )
1823
+ assert_same_number(
1824
+ Float('0X1.5555555555555P-2'), # 0.3333333333333333
1825
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Float)
1826
+ )
1827
+ assert_same_number(
1828
+ Float('0X1.5555555555555P-2'), # 0.3333333333333333
1829
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Float)
1830
+ )
1831
+ assert_same_number(
1832
+ Float('0X1.5555551C112DAP-2'), # 0.33333333
1833
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Float)
1834
+ )
1835
+ assert_same_number(
1836
+ Float('0X1.5555551C112DAP-2'), # 0.33333333
1837
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Float)
1838
+ )
1839
+ assert_same_number(
1840
+ Float('0X1.5555551C112DAP-2'), # 0.33333333
1841
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Float)
1842
+ )
1843
+ assert_same_number(
1844
+ Flt::BinNum[1, 6004799503160661, -54], # 0.3333333333333333
1845
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::BinNum)
1846
+ )
1847
+ assert_same_number(
1848
+ Flt::BinNum[1, 6004799503160661, -54], # 0.3333333333333333
1849
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::BinNum)
1850
+ )
1851
+ assert_same_number(
1852
+ Flt::BinNum[1, 6004799503160661, -54], # 0.3333333333333333
1853
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::BinNum)
1854
+ )
1855
+ assert_same_number(
1856
+ Flt::BinNum[1, 22369621, -26], # 0.33333333
1857
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::BinNum)
1858
+ )
1859
+ assert_same_number(
1860
+ Flt::BinNum[1, 89478484, -28], # 0.33333333
1861
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::BinNum)
1862
+ )
1863
+ assert_same_number(
1864
+ Flt::BinNum[1, 6004799443112666, -54], # 0.33333333
1865
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::BinNum)
1866
+ )
1867
+ assert_same_number(
1868
+ DecNum('0.333333333'),
1869
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Flt::DecNum)
1870
+ )
1871
+ assert_same_number(
1872
+ DecNum('0.333333333'),
1873
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Flt::DecNum)
1874
+ )
1875
+ assert_same_number(
1876
+ DecNum('0.333333333'),
1877
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Flt::DecNum)
1878
+ )
1879
+ assert_same_number(
1880
+ DecNum('0.33333333'),
1881
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Flt::DecNum)
1882
+ )
1883
+ assert_same_number(
1884
+ DecNum('0.33333333'),
1885
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Flt::DecNum)
1886
+ )
1887
+ assert_same_number(
1888
+ DecNum('0.333333330'),
1889
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Flt::DecNum)
1890
+ )
1891
+ assert_same_number(
1892
+ Rational(1, 3),
1893
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :short, type: Rational)
1894
+ )
1895
+ assert_same_number(
1896
+ Rational(1, 3),
1897
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :free, type: Rational)
1898
+ )
1899
+ assert_same_number(
1900
+ Rational(1, 3),
1901
+ Conversions.convert(x, exact_input: true, rounding:[:free], output_mode: :fixed, type: Rational)
1902
+ )
1903
+ assert_same_number(
1904
+ Rational(33333333, 100000000),
1905
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :short, type: Rational)
1906
+ )
1907
+ assert_same_number(
1908
+ Rational(33333333, 100000000),
1909
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :free, type: Rational)
1910
+ )
1911
+ assert_same_number(
1912
+ Rational(33333333, 100000000),
1913
+ Conversions.convert(x, exact_input: true, rounding:[precision: 8], output_mode: :fixed, type: Rational)
1914
+ )
1915
+
1916
+
1917
+ end
1918
+
1919
+
1920
+
1921
+ end