Looking for "round towards 0" function.

Roy Smith roy at alanine.phri.nyu.edu
Mon Dec 18 03:08:21 AEST 1989


	I want to round a (possibly negative) double towards zero (ending
up with another double).  As far as I can tell, what I need to do is

	x2 = copysign (floor (fabs (x1))), x1);

but it seems like there should be a simplier way.  Is there?  If it helps,
I can guarantee that the integral part of the double will fit into an int
with no loss of precision (i.e. -90 <= x <= 90).
--
Roy Smith, Public Health Research Institute
455 First Avenue, New York, NY 10016
roy at alanine.phri.nyu.edu -OR- {att,philabs,cmcl2,rutgers,hombre}!phri!roy
"My karma ran over my dogma"



More information about the Comp.lang.c mailing list