Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!umd5!brl-adm!brl-smoke!gwyn
From: gwyn@brl-smoke.ARPA (Doug Gwyn )
Newsgroups: comp.lang.c
Subject: Re: Floor function w/out math library
Message-ID: <6757@brl-smoke.ARPA>
Date: Sat, 28-Nov-87 22:04:25 EST
Article-I.D.: brl-smok.6757
Posted: Sat Nov 28 22:04:25 1987
Date-Received: Tue, 1-Dec-87 03:29:22 EST
References: <5103@zen.berkeley.edu>
Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) )
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 17

In article <5103@zen.berkeley.edu> taranto@cory.Berkeley.EDU (Roger Taranto) writes:
>Does anyone have a C function to calculate the floor of a number
>without using the math library?

I'm not sure what you would consider to be in the "math library",
but there is supposed to be a floor() function in the standard C
library.  If for some reason you don't want to use this, and if
the range of values you want to convert are not too large in
magnitude, consider exploiting the truncation done by the
language when a floating-point quantity is converted to an integer:

	double floor( double x )
		{
		return x >= 0 ? (unsigned long)x :
			(unsigned long)-x == -x ? x :
				-1.0 - (unsigned long)-x;
		}