Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

What is floorf() in C?

Abdul Monum

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

floorf() in C is used to calculate the largest integer value not greater than the argument value. floorf() is defined in the math.h header file and the function declaration is as follows:

float floorf(float arg);

Parameters and return value

arg: floating point value

Return value: largest integer value not greater than arg

Example program

#include <math.h>
#include <stdio.h>
int main(void)
{
printf("floor(+3.0) = %.1f\n", floorf(3.0));
printf("floor(+3.9) = %.1f\n", floorf(3.9));
printf("floor(-3.9) = %.1f\n", floorf(-3.9));
printf("floor(-0.0) = %.1f\n", floorf(-0.0));
printf("floor(0.0) = %.1f\n", floorf(0.0));
/* special cases */
printf("floor(inf) = %.1f\n", floorf(INFINITY));
printf("floor(-inf) = %.1f\n", floorf(-INFINITY));
printf("floorf = %f\n", floorf(NAN));
return 0;
}

Explanation

First, we import the math.h header file from the C standard library. The program then simply prints the output of floorf() on possible example values.

RELATED TAGS

CONTRIBUTOR

Abdul Monum
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring