## Linux and UNIX Man Pages

Test Your Knowledge in Computers #599
Difficulty: Medium
For modern C programming, defining functions is a two step process. First, you declare a function and its signature using a prototype. Then you define the function by providing a function body that defines what the function does.
True or False?

# 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.

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.

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

RISC								 floor(3m)```

## 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

## 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) =...

## 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

## 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,

## 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); ...

## 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 ...

## 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...

## 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...

## 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...

## 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.

## 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...

## 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