C++ Standard Library C++ STL Library

C++ <cinttypes> - imaxabs() Function



The C++ <cinttypes> imaxabs() function returns the absolute value (positive value) of the specified integral value. For example - absolute value of integral value x will be |x|.

Note: This function is equivalent to abs() function for intmax_t.

Syntax

intmax_t imaxabs (intmax_t x);                                    

Parameters

x Specify an integral value whose absolute value need to be determined.

Return Value

Returns the absolute value (positive value) of integral argument.

Example:

The example below shows the usage of <cinttypes> imaxabs() function.

#include <iostream>
#include <cinttypes>
using namespace std;
 
int main (){
  cout<<"imaxabs(10) = "<<imaxabs(10)<<"\n";
  cout<<"imaxabs(-10) = "<<imaxabs(-10)<<"\n";
  cout<<"imaxabs(50) = "<<imaxabs(-50)<<"\n";
  cout<<"imaxabs(-50) = "<<imaxabs(50)<<"\n";  
  return 0;
}

The output of the above code will be:

imaxabs(10) = 10
imaxabs(-10) = 10
imaxabs(50) = 50
imaxabs(-50) = 50

❮ C++ <cinttypes> Library