__builtin_inf() functions of GCC compiler
Last Updated :
02 Sep, 2021
These functions do not need to include any header file to use them. So it provides faster usage, as these are Built-in functions of GCC compiler which is most used compiler, even in competitive programming.
Note: If the compiler shows warning of overflow, use casting before __builtin_inf() function as
(data_type)__builtin_inf()
1. __builtin_inf(void): This function returns positive infinity which will then be converted to DBL_MAX of C language limits.h header file Macro. Its return data type is double.
Example:
if __builtin_inf() is used
it returns infinite
Output: inf
Here is a C++ program that shows the use of this function:
C++
#include <iostream>
using namespace std;
int main()
{
// infinite value (<b>inf</b>)
double double_inf = __builtin_inf();
cout << double_inf << endl;
return 0;
}
2. __builtin_infd32(void): This function returns maximum value of 4-byte integer and returns data type is 32-bit integer.
Example:
if __builtin_infd32() is used
it returns the maximum value of
the 32-bit integer
Output: 2147483647
Here is a C++ program which shows the use of this function:
C++
#include <iostream>
using namespace std;
int main()
{
// function returns highest signed integer value
int int_inf = (int)__builtin_infd32();
// you can use __builtin_inf() function
// as well and then cast to integer
int int_inf2 = (int)__builtin_inf();
cout << int_inf << endl;
cout << int_inf2 << endl;
// function returns highest unsigned integer value
unsigned int unsinged_int_inf
= (unsigned int)__builtin_infd32();
// you can use __builtin_inf() function as well
// and then cast to unsigned integer
unsigned int unsinged_int_inf2
= (unsigned int)__builtin_inf();
cout << unsinged_int_inf << endl;
cout << unsinged_int_inf2 << endl;
return 0;
}
Output: 2147483647
2147483647
4294967295
4294967295
3. __builtin_infd64(void): This function returns Highest value that can be represented by 8 byte integer which is highest value of integer we can use in C++.
Example:
if __builtin_infd64() is used
it returns the maximum value of
the 64-bit integer
Output: 9223372036854775807
Here is a C++ program which shows the use of this function:
C++
#include <iostream>
using namespace std;
int main()
{
// highest signed 8 byte value
long long int long_inf = (long long int)__builtin_infd64();
// you can use __builtin_inf() as well
// and then cast to long long int
long long int long_inf2
= (long long int)__builtin_inf();
cout << long_inf << endl;
cout << long_inf2 << endl;
// highest unsigned 8 byte value
unsigned long long int unsigned_longlong_inf
= (unsigned long long int)__builtin_infd64();
// you can use __builtin_inf() as well
// and then cast to unsigned long long int
unsigned long long int unsigned_longlong_inf2
= (unsigned long long int)__builtin_inf();
cout << unsigned_longlong_inf << endl;
cout << unsigned_longlong_inf2 << endl;
return 0;
}
Output: 9223372036854775807
9223372036854775807
18446744073709551615
18446744073709551615
4. __builtin_infd128(void): As the maximum size that can be used for integer is 64-bit in C/C++, this function give the same result as __builtin_infd64().
Example:
if __builtin_infd128() is used
it returns the maximum value of
the 64-bit integer
Output: 9223372036854775807
5. __builtin_inff(void): This function returns float maximum value means 4-byte maximum decimal point value.
Example:
if __builtin_inff() is used
it returns the maximum value of
the 32-bit float
Output: inf
Here is a C++ program which shows the use of this function:
C++
#include <iostream>
using namespace std;
int main()
{
float float_inf = __builtin_inff();
// you can use __builtin_inf() as well
// and then cast it to float data type
float float_inf2 = (float)__builtin_inf();
cout << float_inf << endl;
cout << float_inf2 << endl;
return 0;
}
6. __builtin_infl(void): This function returns maximum long double data type value.
Example:
if __builtin_infl() is used
it returns the maximum value of
the long double type
Output: inf
Here is a C++ program which shows the use of this function:
C++
#include <iostream>
using namespace std;
int main()
{
long double long_double_inf = __builtin_infl();
// you can use __builtin_inf() as well
// and then cast it to float data type
long double long_double_inf2
= (long double)__builtin_inf();
cout << long_double_inf << endl;
cout << long_double_inf2 << endl;
return 0;
}
7. In the recent versions of GCC compiler, these are two new functions: __builtin_infn(void) & __builtin_infnx(void). One can replace n with 32 or 64 and it will return inf value respectively of 32-bit, 64-bit.
Similar article: Builtin functions of GCC compiler
Similar Reads
Builtin functions of GCC compiler
These are four important built-in functions in GCC compiler: 1. __builtin_popcount(x) This function is used to count the number of one's(set bits) in an integer. Example: if x = 4 binary value of 4 is 100 Output: No of ones is 1. C // C program to illustrate _builtin_popcount(x) #include <stdio.h
3 min read
exec family of functions in C
The exec family of functions is defined in the unistd.h header file. The exec functions are used to replace the current running process with a new process. It can be used to run a C program by using another C program.Exec functions in CThere are many members in the exec family, which are shown below
5 min read
asin() function for complex number in C++
The asin() function for complex numbers is defined in the complex header file. This function is the complex version of the asin() function. This function is used to calculate the complex arc sine of complex number z and returns the arc sine of complex number z. Syntax: template<class T> comple
2 min read
asinh() function for complex number in C++
The asinh() function for complex numbers is defined in the complex header file. This function is the complex version of the asinh() function. This function is used to calculate the complex arc hyperbolic sine of complex number z and returns the arc hyperbolic sine of complex number z. Syntax: templa
2 min read
asinh() function in C++ STL
The asinh() is an inbuilt function in C++ STL that returns the inverse hyperbolic sine of an angle given in radians. The function belongs to <cmath> header file.Syntax:Â asinh(data_type x) Time Complexity: O(1)Auxiliary Space: O(1) Parameter: The function accepts one mandatory parameter x whic
3 min read
norm() function in C++ with Examples
The norm() function is defined in the complex header file. This function is used to return the squared magnitude of the complex number z. Syntax: template<class T> T norm (const complex<T>& z); Parameter: z: It represents the given complex number. Return: It returns the squared magni
1 min read
Functions in C++
A function is a building block of C++ programs that contains a set of statements which are executed when the functions is called. It can take some input data, performs the given task, and return some result. A function can be called from anywhere in the program and any number of times increasing the
9 min read
getx() function in C
The header file graphics.h contains getx() function which returns the X coordinate of the current position. Syntax : int getx(); Example : Explanation : Initially, the X coordinate of the current position is 0. On moving the coordinates using moveto() function, the X coordinate changes to 80. Below
2 min read
atexit() function in C/C++
The function pointed by atexit() is automatically called without arguments when the program terminates normally. In case more than one function has been specified by different calls to the atexit() function, all are executed in the order of a stack (i.e. the last function specified is the first to b
3 min read
GNU Compiler Collection
Pre-requisites: Introduction to Compiler Design GCC is an essential tool for software developers since it offers a potent, adaptable, and portable suite of compilers for a number of programming languages. Due to its support for modern standards, efficient code production, and extensive development e
3 min read