aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-08-21 12:37:46 +0200
committerMarco Paland <marco@paland.com>2018-08-21 12:37:46 +0200
commite6b5331a36a5815cc36a9b2872f29234efee72cb (patch)
tree53519bcfd31b2663c749f86ddc1cfdcc388ea911 /test
parent61de9c0cb0738e51625b6071a88921fecd591180 (diff)
downloadprintf-e6b5331a36a5815cc36a9b2872f29234efee72cb.tar.gz
printf-e6b5331a36a5815cc36a9b2872f29234efee72cb.tar.bz2
printf-e6b5331a36a5815cc36a9b2872f29234efee72cb.zip
fix(printf): fix floating point precision limit
Return the correct count of precision digits now. Fixes #22
Diffstat (limited to 'test')
-rw-r--r--test/test_suite.cpp12
1 files changed, 11 insertions, 1 deletions
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"));