aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-04-16 14:04:28 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-04-16 14:04:28 +0100
commitee201b7a8c5a1116f3aae19de68520d9fc7391d3 (patch)
treef16fc38e7856dafd354439d09daa01b7f549be94 /contrib
parent277d0a32c3327a92fde4a9c8de15e51d2d4c6e89 (diff)
downloadrspamd-ee201b7a8c5a1116f3aae19de68520d9fc7391d3.tar.gz
rspamd-ee201b7a8c5a1116f3aae19de68520d9fc7391d3.zip
[Fix] Fix floating point printing
Diffstat (limited to 'contrib')
-rw-r--r--contrib/fpconv/fpconv.c11
-rw-r--r--contrib/fpconv/fpconv.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/contrib/fpconv/fpconv.c b/contrib/fpconv/fpconv.c
index 3fbd55af0..12c67cfa6 100644
--- a/contrib/fpconv/fpconv.c
+++ b/contrib/fpconv/fpconv.c
@@ -99,7 +99,7 @@ static Fp multiply(Fp* a, Fp* b)
uint64_t al_bl = (a->frac & lomask) * (b->frac & lomask);
uint64_t ah_bh = (a->frac >> 32) * (b->frac >> 32);
- uint64_t tmp = (ah_bl & lomask) + (al_bh & lomask) + (al_bl >> 32);
+ uint64_t tmp = (ah_bl & lomask) + (al_bh & lomask) + (al_bl >> 32);
/* round up */
tmp += 1U << 31;
@@ -206,7 +206,8 @@ static int grisu2(double d, char* digits, int* K)
return generate_digits(&w, &upper, &lower, digits, K);
}
-static int emit_digits(char* digits, int ndigits, char* dest, int K, bool neg)
+static int emit_digits(char* digits, int ndigits, char* dest, int K, bool neg,
+ bool scientific)
{
int exp = absv(K + ndigits - 1);
@@ -219,7 +220,7 @@ static int emit_digits(char* digits, int ndigits, char* dest, int K, bool neg)
}
/* write decimal w/o scientific notation */
- if(K < 0 && (K > -7 || exp < 4)) {
+ if(scientific && (K < 0 && (K > -7 || exp < 4))) {
int offset = ndigits - absv(K);
/* fp < 1.0 -> write leading zero */
if(offset <= 0) {
@@ -304,7 +305,7 @@ static int filter_special(double fp, char* dest)
return 3;
}
-int fpconv_dtoa(double d, char dest[24])
+int fpconv_dtoa(double d, char dest[24], bool scientific)
{
char digits[18];
@@ -326,7 +327,7 @@ int fpconv_dtoa(double d, char dest[24])
int K = 0;
int ndigits = grisu2(d, digits, &K);
- str_len += emit_digits(digits, ndigits, dest + str_len, K, neg);
+ str_len += emit_digits(digits, ndigits, dest + str_len, K, neg, scientific);
return str_len;
}
diff --git a/contrib/fpconv/fpconv.h b/contrib/fpconv/fpconv.h
index 58bbcccbb..83180d41f 100644
--- a/contrib/fpconv/fpconv.h
+++ b/contrib/fpconv/fpconv.h
@@ -26,7 +26,7 @@
*
*/
-int fpconv_dtoa(double fp, char dest[24]);
+int fpconv_dtoa(double fp, char dest[24], bool scientific);
#endif