summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-01-13 19:59:22 +0900
committerKOBAYASHI Shuji <[email protected]>2019-01-13 19:59:22 +0900
commit9f081183d2351195c821fbe1520975ba000cafb5 (patch)
treedbe9017589efa225bb520a3d7e1adbf70f83ef46 /test
parentc1b92f88a210d018b653dc9865fe5375cf118a61 (diff)
downloadmruby-9f081183d2351195c821fbe1520975ba000cafb5.tar.gz
mruby-9f081183d2351195c821fbe1520975ba000cafb5.zip
Improve compatibility to CRuby for `Float#to_s`
Bfore: Float::INFINITY.to_s #=> "inf" 50.0.to_s #=> "50" 1e20.to_s #=> "1e+20" After / CRuby: Float::INFINITY.to_s #=> "Infinity" 50.0.to_s #=> "50.0" 1e20.to_s #=> "1.0e+20"
Diffstat (limited to 'test')
-rw-r--r--test/t/float.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/t/float.rb b/test/t/float.rb
index 68fd31b9a..eac5c5792 100644
--- a/test/t/float.rb
+++ b/test/t/float.rb
@@ -206,4 +206,37 @@ assert('Float#>>') do
assert_equal(-1, -23.0 >> 128)
end
+assert('Float#to_s') do
+ uses_float = 4e38.infinite? # enable MRB_USE_FLOAT?
+
+ assert_equal("Infinity", Float::INFINITY.to_s)
+ assert_equal("-Infinity", (-Float::INFINITY).to_s)
+ assert_equal("NaN", Float::NAN.to_s)
+ assert_equal("0.0", 0.0.to_s)
+ assert_equal("-0.0", -0.0.to_s)
+ assert_equal("-3.21", -3.21.to_s)
+ assert_equal("50.0", 50.0.to_s)
+ assert_equal("0.00021", 0.00021.to_s)
+ assert_equal("-0.00021", -0.00021.to_s)
+ assert_equal("2.1e-05", 0.000021.to_s)
+ assert_equal("-2.1e-05", -0.000021.to_s)
+ assert_equal("1.0e+20", 1e20.to_s)
+ assert_equal("-1.0e+20", -1e20.to_s)
+ assert_equal("1.0e+16", 10000000000000000.0.to_s)
+ assert_equal("-1.0e+16", -10000000000000000.0.to_s)
+ assert_equal("100000.0", 100000.0.to_s)
+ assert_equal("-100000.0", -100000.0.to_s)
+ if uses_float
+ assert_equal("1.0e+08", 100000000.0.to_s)
+ assert_equal("-1.0e+08", -100000000.0.to_s)
+ assert_equal("1.0e+07", 10000000.0.to_s)
+ assert_equal("-1.0e+07", -10000000.0.to_s)
+ else
+ assert_equal("1.0e+15", 1000000000000000.0.to_s)
+ assert_equal("-1.0e+15", -1000000000000000.0.to_s)
+ assert_equal("100000000000000.0", 100000000000000.0.to_s)
+ assert_equal("-100000000000000.0", -100000000000000.0.to_s)
+ end
+end
+
end # const_defined?(:Float)