(trunk libT) #3521 "rounding issue in tr_truncd()" -- fixed.

This commit is contained in:
Charles Kerr 2010-10-11 15:05:24 +00:00
parent eb31da8fad
commit de4ab85030
1 changed files with 2 additions and 4 deletions

View 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*