Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ceil(3m) [bsd man page]

FLOOR(3M)																 FLOOR(3M)

NAME
fabs, floor, ceil, rint - absolute value, floor, ceiling, and round-to-nearest functions SYNOPSIS
#include <math.h> double floor(x) double x; double ceil(x) double x; double fabs(x) double x; double rint(x) double x; DESCRIPTION
Fabs returns the absolute value |x|. Floor returns the largest integer no greater than x. Ceil returns the smallest integer no less than x. Rint returns the integer (represented as a double precision number) nearest x in the direction of the prevailing rounding mode. NOTES
On a VAX, rint(x) is equivalent to adding half to the magnitude and then rounding towards zero. In the default rounding mode, to nearest, on a machine that conforms to IEEE 754, rint(x) is the integer nearest x with the additional stipulation that if |rint(x)-x|=1/2 then rint(x) is even. Other rounding modes can make rint act like floor, or like ceil, or round towards zero. Another way to obtain an integer near x is to declare (in C) double x; int k; k = x; Most C compilers round x towards 0 to get the integer k, but some do otherwise. If in doubt, use floor, ceil, or rint first, whichever you intend. Also note that, if x is larger than k can accommodate, the value of k and the presence or absence of an integer overflow are hard to predict. SEE ALSO
abs(3), ieee(3M), math(3M) 4th Berkeley Distribution May 12, 1986 FLOOR(3M)

Check Out this Related Man Page

floor(3m)																 floor(3m)

Name
       floor,  ffloor,	fabs,  ceil,  ceil,  trunc,  ftrunc, fmod, rint - floor, absolute value, ceiling, truncation, floating point remainder and
       round-to-nearest functions

Syntax
       #include <math.h>

       double floor(x)
       double x;

       float ffloor(x)
       float x;

       double ceil(x)
       double x;

       float fceil(x)
       float x;

       double trunc(x)
       double x;

       float ftrunc(x)
       float x;

       double fabs(x)
       double x;

       double fmod (x, y)
       double x, y;

       double rint(x)
       double x;

Description
       The and routines return the largest integer which is not greater than x for double and float data types, respectively.

       The and routines return the smallest integer which is not less than x for double and float data types, respectively.

       The and routines return the integer (represented as a floating-point number) of x with the fractional bits truncated for double	and  float
       data types respectively.

       The routine returns the absolute value |x|.

       The  routine returns the floating point remainder of the division of x by y: zero if y is zero or if x/y would overflow; otherwise the num-
       ber f with the same sign as x, such that x = iy + f for some integer i, and |f| < |y|.

       The routine returns the integer (represented as a double precision number) nearest x in the direction of the prevailing rounding mode.

       In the default rounding mode, to nearest, is the integer nearest x with the additional stipulation that if |rint(x)-x|=1/2  then  is  even.
       Other rounding modes can make act like or or round towards zero.

       Another way to obtain an integer near x is to declare (in C)
	      double x;     int k;    k = x;
       The  C  compiler  rounds  x  towards 0 to get the integer k.  Also note that, if x is larger than k can accommodate, the value of k and the
       presence or absence of an integer overflow are hard to predict.

       The routine is in libc.a rather than libm.a.

See Also
       abs(3), ieee(3m), math(3m)

								       RISC								 floor(3m)
Man Page

12 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

double dashes

function date_diff { integer _dt1=$(date_to_num ${1:?}) integer _dt2=$(date_to_num ${2:?}) integer _ndt=0 if ] then ((_ndt=_dt2-_dt1)) fi print -- $_ndt } What does double dash '--' indicate ? Can anyone please answer this (2 Replies)
Discussion started by: systemsb
2 Replies

2. Shell Programming and Scripting

FLOOR Func

Hello Experts, Is there any inbuild FLOOR function to do FLOOR func in mathmetics in awk script like in FlOOR Func in C. Ex:- floor(2.9) = 2 floor(2.1) = 2 floor(2.0) = 2 floor(-2.0) = 2 floor(-2.1) = -3 floor(-2.9) =... (1 Reply)
Discussion started by: user_prady
1 Replies

3. UNIX for Dummies Questions & Answers

finding nearest numbers

Hey guys I would like to know how to find nearest numbers based on second column in 1st column some thing like this Input col1 col2 10 20 30 40 48 64 55 71 70 90 output col1 col2 col3 10 20 30 30 40 48 48 64 70 55 71 70 90 (1 Reply)
Discussion started by: bogu0001
1 Replies

4. UNIX for Dummies Questions & Answers

match nearest

Hi, I'm trying to find the nearest match between two columns of numbers, e.g. 1,1 10,8 30,50 20,100 and the search could be e.g. 20,20 returning 10,8 - i.e. 20-10 = 10 and 20-8 = 12 totalling 22, and hence being the nearest match. any ideas? thanks a lot, (1 Reply)
Discussion started by: bogu0001
1 Replies

5. Programming

Java double subtraction oddity (not the usual rounding discrepancy)

I've been going through a java tutorial, and ran across some strangeness in this small example... class SqrRoot { public static void main(String args) { double num,sroot,rerr,resquare; for(num = 1.0; num < 100.0; num++) { sroot = Math.sqrt(num); ... (1 Reply)
Discussion started by: Trones
1 Replies

6. Shell Programming and Scripting

How to round up on fives in unix?

i'm a newbie here, i need help with a shell script. for a given number, if it is greater than ten round to the nearest 10 same for 100, if it is greater than 100 round to the nearest 100, and same for 1000. i'm confused how to start this... its supposed to look like this input ... (11 Replies)
Discussion started by: CRAZYLITTLELOU
11 Replies

7. Shell Programming and Scripting

CEILING and FLOOR functions

Hi all, Does anyone know how to simulate a ceiling or floor function in UNIX? OS is Solaris. I tried the suggestion from an old forum but it is giving me error as below: server01/tmp$: echo "7.2" | awk '{printf("%d\n",$0+=$0<0?0:0.999)}' awk: syntax error near line 1 awk: illegal... (3 Replies)
Discussion started by: newbie_01
3 Replies

8. Shell Programming and Scripting

Ceil not working as function in awk statement

Hi, I have the following code in which i am trying to find ceil of 10th & 11th fields. For finding ceil i have a function in the awk statement. When i test it for some values say on command line it gives correct response(say $10=0 & $11=750). But when the same value occurs in a file having more 3... (5 Replies)
Discussion started by: siramitsharma
5 Replies

9. UNIX for Dummies Questions & Answers

How to restrict Rounding using Printf?

Hello, I am using bash shell on Linux OS, May i please know why is it rounding for big numbers but not for others, is there a workaround to print it as it is with out round off? printf '%'\''.2f\n' 9999999999999999999.99 10,000,000,000,000,000,000.00 printf '%'\''.2f\n' 99999999999999.99... (1 Reply)
Discussion started by: Ariean
1 Replies

10. UNIX for Dummies Questions & Answers

Rounding off a decimal

How to round off a decimal number to higher whole number using ceil command in unix? Eg. 4.41 or 4.11 or 4.51 should be rounded off to 5. (11 Replies)
Discussion started by: SanjayKumar28
11 Replies

11. Programming

Round floor behavior

Hello, My round and floor functions in C program behaves weird. Can someone help resolve the issue.. fprintf( fp, "ROUND TEST VARIABLE 11686776.000000 %d\n", round(11686776.000000)); fprintf( fp, "ROUND TEST VARIABLE 1168677.000000 %d\n", round(1168677.000000)); fprintf( fp, "FLOOR... (3 Replies)
Discussion started by: anijan
3 Replies

12. UNIX for Beginners Questions & Answers

Mp3 duration rounded up to nearest seconds

Hi, can anyone provide more details to why an audio file's duration is seen as 10 seconds on unix and 9 seconds on windows Read about windows MFT rounding down to nearest seconds, is there any article on unix rounding up? thanks in advance (1 Reply)
Discussion started by: wsps1750
1 Replies