From 9f081183d2351195c821fbe1520975ba000cafb5 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sun, 13 Jan 2019 19:59:22 +0900 Subject: 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" --- test/t/float.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/t') 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) -- cgit v1.2.3