]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3521 "rounding issue in tr_truncd()" -- fixed.
authorCharles Kerr <charles@transmissionbt.com>
Mon, 11 Oct 2010 15:05:24 +0000 (15:05 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 11 Oct 2010 15:05:24 +0000 (15:05 +0000)
libtransmission/utils.c

index c76d9988101dc54e5d16cca7f018679b7197be90..13c5f45bbeb862ad433a122f037abe45c3fd5df3 100644 (file)
@@ -24,7 +24,7 @@
 #include <assert.h>
 #include <ctype.h> /* isalpha(), tolower() */
 #include <errno.h>
-#include <math.h> /* pow(), fabs() */
+#include <math.h> /* pow(), fabs(), floor() */
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1386,9 +1386,7 @@ double
 tr_truncd( double x, int decimal_places )
 {
     const int i = (int) pow( 10, decimal_places );
-    const double xup = x * i;
-    const double x2 = (int64_t)(xup);
-    return x2 / i;
+    return floor( x * i ) / i;
 }
 
 char*