From c286775d9f65dde5071d56936ffd19db4425cca9 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 21 Nov 2022 07:41:41 +0200 Subject: [PATCH] strconv: add test_atof_converter to the tests, as suggested by the code review --- vlib/strconv/converter_test.v | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/vlib/strconv/converter_test.v b/vlib/strconv/converter_test.v index 1a1651126b..e43b4ff541 100644 --- a/vlib/strconv/converter_test.v +++ b/vlib/strconv/converter_test.v @@ -6,6 +6,29 @@ fn test_issue_16448() { assert float_prec < 2.01 } +fn test_atof_converter() { + mut float_prec := 1.9999999999999999 + 0.0000000000000000005 + assert float_prec == 2.0 + float_prec = 3.9999999999999999 + 0.0000000000000000005 + assert float_prec == 4.0 + float_prec = -3.9999999999999999 - 0.0000000000000000005 + assert float_prec == -4.0 + float_prec = -1.9999999999999999 - 0.0000000000000000005 + assert float_prec == -2.0 + float_prec = 0.025 + 0.0000000000000000005 + assert float_prec == 0.025 + float_prec = 0.0625 + 0.0000000000000000005 + assert float_prec == 0.0625 + float_prec = 0.0009765625 + 0.0000000000000000005 + assert float_prec > 0.00097656250 && float_prec < 0.00097656251 + float_prec = -0.025 - 0.0000000000000000005 + assert float_prec == -0.025 + float_prec = -0.0625 - 0.0000000000000000005 + assert float_prec == -0.0625 + float_prec = -0.0009765625 - 0.0000000000000000005 + assert float_prec < -0.00097656250 && float_prec > -0.00097656251 +} + // Testing all the numbers between -100E6..100E6 takes over a minute with clang on i3 // while for just -1E5..1E5, it takes less than a second. // const r = i64(100_000_001)