From e6b5331a36a5815cc36a9b2872f29234efee72cb Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Tue, 21 Aug 2018 12:37:46 +0200 Subject: fix(printf): fix floating point precision limit Return the correct count of precision digits now. Fixes #22 --- test/test_suite.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_suite.cpp b/test/test_suite.cpp index 3d7c10d..212fbd3 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -933,7 +933,17 @@ TEST_CASE("float", "[]" ) { REQUIRE(!strcmp(buffer, "42.895200000")); test::sprintf(buffer, "%.10f", 42.895223); - REQUIRE(!strcmp(buffer, "42.895223000")); + REQUIRE(!strcmp(buffer, "42.8952230000")); + + // this testcase checks, that the precision is truncated to 9 digits. + // a perfect working float should return the whole number + test::sprintf(buffer, "%.12f", 42.89522312345678); + REQUIRE(!strcmp(buffer, "42.895223123000")); + + // this testcase checks, that the precision is truncated AND rounded to 9 digits. + // a perfect working float should return the whole number + test::sprintf(buffer, "%.12f", 42.89522387654321); + REQUIRE(!strcmp(buffer, "42.895223877000")); test::sprintf(buffer, "%6.2f", 42.8952); REQUIRE(!strcmp(buffer, " 42.90")); -- cgit v1.2.3