From 501f7ed8af26a72d3e6399dc137cfd93d7ee263b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 25 Sep 2019 10:42:06 +0200 Subject: [PATCH] [poincare] PrintFloat: create glyphLengthForFloatWithPrecision --- poincare/include/poincare/print_float.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/poincare/include/poincare/print_float.h b/poincare/include/poincare/print_float.h index df15776ae..37c71440d 100644 --- a/poincare/include/poincare/print_float.h +++ b/poincare/include/poincare/print_float.h @@ -19,9 +19,22 @@ public: * always shorter. */ constexpr static int k_maxFloatBufferSize = 2+k_numberOfStoredSignificantDigits+k_specialECodePointByteLength+1+3+1; + constexpr static int glyphLengthForFloatWithPrecision(int numberOfSignificantDigits) { + // The worst case is -1.234ᴇ-328 + return 2 // '-' and '.' + + numberOfSignificantDigits // mantissa + + 1 // glyph ᴇ + + 1 // '-' + + 3; // exponant + } constexpr static int bufferSizeForFloatsWithPrecision(int numberOfSignificantDigits) { // The worst case is -1.234ᴇ-328 - return 2+numberOfSignificantDigits+k_specialECodePointByteLength+1+3+1; + return 2 // '-' and '.' + + numberOfSignificantDigits // mantissa + + k_specialECodePointByteLength // ᴇ + + 1 // '-' + + 3 // exponant + + 1; // null-terminated buffer } /* If the buffer size is too small to display the right number of significant