[master] 6f51994 We are more worried about mantissa overrun than precision, so use doubles for the mantissa and exponent. This may increase the error by up to one bit in last position.

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 24 09:02:29 CET 2015


commit 6f51994a0f8f4e9eceae4b1e804245d8efd8c620
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 24 08:01:17 2015 +0000

    We are more worried about mantissa overrun than precision, so use doubles
    for the mantissa and exponent.  This may increase the error by up
    to one bit in last position.

diff --git a/lib/libvarnish/vnum.c b/lib/libvarnish/vnum.c
index 6d5d002..5635e45 100644
--- a/lib/libvarnish/vnum.c
+++ b/lib/libvarnish/vnum.c
@@ -53,7 +53,7 @@ static const char err_invalid_suff[] = "Invalid suffix";
 double
 VNUMpfx(const char *p, const char **t)
 {
-	intmax_t m = 0, ee = 0;
+	double m = 0., ee = 0.;
 	double ms = 1.0;
 	double es = 1.0, e = 1.0, ne = 0.0;
 
@@ -68,7 +68,7 @@ VNUMpfx(const char *p, const char **t)
 
 	for (; *p != '\0'; p++) {
 		if (isdigit(*p)) {
-			m = m * 10 + *p - '0';
+			m = m * 10. + *p - '0';
 			e = ne;
 			if (e)
 				ne = e - 1.0;
@@ -86,7 +86,7 @@ VNUMpfx(const char *p, const char **t)
 		if (!isdigit(*p))
 			return (nan(""));
 		for (; isdigit(*p); p++)
-			ee = ee * 10 + *p - '0';
+			ee = ee * 10. + *p - '0';
 	}
 	while (isspace(*p))
 		p++;



More information about the varnish-commit mailing list