Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is fminf in C?

Samia Ishaque

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.

Overview

The fminf() function in C determines the minimum of two floating-point numbers. The function is defined in the <math.h> header file.

To use the fminf() function, you need to include the <math.h> library at the beginning of your program. Below is an example of how you can do this:

#include<math.h>

The fminf() function in C is defined in the <math.h> header file as shown below:

float  fminf( float x, float y );

Parameters

The fminf() function takes two arguments (xx and yy) of type float as input.

Return value

Upon successful executive, the fminf() function returns the minimum of the two numbers. The return type is also float.

On the other hand, varying xx and yy values changes the results for fminf() in the following ways:

  1. If both inputs are Not a Number NaN, the return value is also NaN.
  2. If xx is NaN, fminf() will return yy, and vice versa.

Example

Below is an example of how to use fminf() function, given that xx and yy are 3.23.2 and 2.52.5 respectively. The fminf() function returns the smaller floating point number, which in this case is 2.52.5.

#include<stdio.h>
#include<math.h>

int main() {
    float smallest = fminf(3.2, 2.5);

    printf("The smaller of the two numbers is: %f\n", smallest);
    return 0;
}

The code below demonstrates how varying xx and yy values affect the return value of the fminf() function:

#include<stdio.h>
#include<math.h>

int main() {
    float min1 = fminf(NAN, 2.5);
    printf("The smaller of the two numbers is: %f\n", min1);

    float min2 = fminf(NAN, NAN);
    printf("The smaller of the two numbers is: %f\n", min2);
    return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Samia Ishaque
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