# Ceil, ceill and floor, floorl

The functions ceil and ceill round up the given float number, whereas the functions floor and floorl round down the float number. They are defined in math.h header file. Their declarations are as given below.

Declaration |

Double ceil(double n); Double floor(double n); Long double ceill(long double (n)); Long double floorl(long double (n)); |

The following program illustrates the working of these functions.

**7.26 Write a program to round down and up the given float number.**

**Explanation:** In the above program, the float variable num has a value 3.12. The floor() function converts it to the nearest and small integer number than variable num and returns it to variable d, whereas the ceil() function converts the float number to the nearest and greater number than num. The output of the program is shown above.

# modf and modfI

The function modf breaks double into integer and fraction elements, and the function modfl breaks long double into integer and fraction elements. These functions return the fractional elements of a given number. They are declared as given below.

Declaration |

double modf(double n, double *ip); long double modfl(long double (n), long double *(ip)); |

**7.27 Write a program to separate double number into integer and fractional parts.**

**Explanation:** In the above program, the modf() function separates a double number into separate integer and fractional parts. The second argument of the function is passed by reference that after execution holds the integer part of the number.

# abs, fabs, and labs

The function abs() returns the absolute value of an integer. The fabs() returns the absolute value of a floating-point number, and labs() returns the absolute value of a long number.

Declaration: int abs(int n); double fabs(double n); long int labs(long int n); |

abs: If abs is invoked using STDLIB.H, it is executed as a macro that expands to inline code. If we need to use the original abs function then undefine the macro using statement #undef abs in the program, after the #include<stdlib.h>.

The following program illustrates the working of these functions.

**7.28 Write a program to display the absolute number of an integer, float, and long integer.**

**Explanation:** In the above program, the function abs() returns the absolute value of a negative number â€“1874. The fabs() function returns the absolute value of a floating-point number. The labs() function returns the absolute value of long number. In the statement long n = âˆ’12252111L, the L tells the compiler that the number is of long data type and provides storage equal to and as required for long data type.

# norm

This function is defined in complex.h header file and it is used to calculate the square of the absolute value.

Syntax: double norm(complex n); |

**7.29 Write a program to calculate the square of the complex number using norm() function.**

**Explanation: **In the above program the norm() function calculates the square of complex negative number.

# complex(), real(), imag(), and conj()

**complex():** This function is defined in complex.h header file and it creates complex numbers from given real and imaginary parts. The imaginary part is supposed to be 0 if not given. Complex is the constructor for C++ class complex. This function returns the complex number with the given real and imaginary parts.

**real():** Returns real part of the complex number.

**imag():** Returns the imaginary part of the complex number.

**conj():** Returns complex conjugate of a complex number.

Syntax: complex complex(double real, double imag); Syntax: double real(complex x); Syntax: double imag(complex x); Syntax: double conj(complex x); |

**7.30 Write a program to return real, imaginary part and conjugate number.**

**Explanation:** In the above program variable a and b of double data type are declared and initialized with 4.5 and 7.4. By applying the complex(), imag() ad conj() functions results are obtained. The results are shown in the output.