From c58b829709f8850713d6b81a8995f6da78fbf2e7 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Sat, 11 Oct 2014 22:15:37 +0000 Subject: [PATCH] Make float_format(uintE) more precise. Due to a typo in the binary representation lfo ln(10)/ln(2), this function could preduce slightly wrong sizes for really huge arguments. --- src/float/misc/cl_float_format.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/float/misc/cl_float_format.cc b/src/float/misc/cl_float_format.cc index 62a81e4..a11a244 100644 --- a/src/float/misc/cl_float_format.cc +++ b/src/float/misc/cl_float_format.cc @@ -16,8 +16,8 @@ float_format_t float_format (uintE n) // Methode: // Mindestens 1+n Dezimalstellen (inklusive Vorkommastelle) // bedeutet mindestens ceiling((1+n)*ln(10)/ln(2)) Binärstellen. -// ln(10)/ln(2) = 3.321928095 = (binär) 11.0101001001101001111000010010111100110100... -// = (binär) 100 - 0.1010110110010110000111101101000111001011... +// ln(10)/ln(2) = 3.321928095 = (binär) 11.010100100110100111100001001011110011010... +// = (binär) 100 - 0.101011011001011000011110110100001100101... // Durch diese Berechnungsmethode wird das Ergebnis sicher >= (1+n)*ln(10)/ln(2) // sein, evtl. um ein paar Bit zu groß aber nicht zu klein. n = 1+n; @@ -28,7 +28,7 @@ float_format_t float_format (uintE n) - (n >> 15) - (n >> 20) - (n >> 21) - (n >> 22) - (n >> 23) - (n >> 25) - (n >> 26) - (n >> 28) #if (intEsize>32) - - (n >> 32) - (n >> 33) - (n >> 34) - (n >> 35) + - (n >> 33) - (n >> 34) - (n >> 37) - (n >> 39) #endif ); }