Math Fmin Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Fmin Function

Math Fmin Function

BLUF: Mastering Math Fmin Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Fmin Function

C++ is renowned for its efficiency. Learn how Math Fmin Function enables low-level control and high-performance computing in the tutorial below.

C++ Math fmin

The function outputs the smallest value between a pair of numbers.

Conditions:

Consider two numbers 'x' and 'y'.

If a condition x is satisfied, the function returns x. If the condition x is greater than y is satisfied, the function returns y. If the condition x is NaN, the function returns y. If the condition y is NaN, the function returns x.

Syntax

Example

float fmin(float x, float y);
double fmin(double x, double y);
long double fmin(long double x, long double y);
promoted fmin(Arithmetic x, Arithmetic y);

Note: If any argument has an integral type, then it is cast to double. If any other argument is long double, then it is cast to long double.

Parameter

(x,y): Range of values within which the calculation of the minimum value is required.

Return value

It returns the minimum value between two numbers.

Example 1

Let's see a simple example.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
   float x=1.1;
   float y=2.1;
   std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
   cout<<"Minimum value is :"<<fmin(x,y);
    return 0;
}

Output:

Output

Values of x and y are :1.1,2.1
Minimum value is :1.1

In this instance, the value assigned to x is lower than that of y. Consequently, the function fmin will provide the value of x.

Example 2

Let's examine a basic scenario where one of the values is NaN.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
   float x=10.1;
   double y=NAN;
   std::cout <<"Values of x and y are :"<<x<<","<<y<< std::endl;
   cout<<"Minimum value is :"<<fmin(x,y);
    return 0;
}

Output:

Output

Values of x and y are :10.1,nan
Minimum value is :10.1

In this scenario, the value of y is NaN. Consequently, the function returns the value of x.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience