double precision rounding


Uses my_double_greater_check from http://rutmandal.info/double-precision-comparison-in-cc/

double my_double_round( double val, int multiplier )
{
         double val_adj = val * multiplier;
         if ( my_double_greater_check( val_adj floor( val_adj ), 0.0 ) > 0 )
                      val = round( val_adj ) / multiplier;
         return val;
}

round and floor are C math library <math.h> functions.

E.g.

double rnd_val = my_double_round( 0.000998, 1000);

rnd_val will be 0.001

Advertisements

પ્રતિસાદ આપો

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / બદલો )

Twitter picture

You are commenting using your Twitter account. Log Out / બદલો )

Facebook photo

You are commenting using your Facebook account. Log Out / બદલો )

Google+ photo

You are commenting using your Google+ account. Log Out / બદલો )

Connecting to %s