std::numeric_limits::digits in C++ with Example

The std::numeric_limits::digits function in C++ STL is present in the <limits> header file. The std::numeric_limits::digits function is used to find the number of radix digits that the data type can represent without loss of precision.

Header File:

#include<limits>

Template:

static const int digits;
static constexpr int digits;

Syntax:

std::numeric_limits<T>::digits

Parameter: The function std::numeric_limits<T>::digits does not accept any parameter.



Return Value: The function std::numeric_limits<T>::digits returns the number of radix digits that the type can represent without loss of precision.

Below is the program to demonstrate std::numeric_limits<T>::digits in C++:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// std::numeric_limits<T>::digits
#include <bits/stdc++.h>
#include <limits>
using namespace std;
  
// Driver Code
int main()
{
    // Print the numeric digit for
    // the various data type
    cout << "For int: "
         << numeric_limits<int>::digits
         << endl;
  
    cout << "For float: "
         << numeric_limits<float>::digits
         << endl;
  
    cout << "For double: "
         << numeric_limits<double>::digits
         << endl;
  
    cout << "For long double: "
         << numeric_limits<long double>::digits
         << endl;
  
    return 0;
}

chevron_right


Output:

For int: 31
For float: 24
For double: 53
For long double: 64

Reference: https://en.cppreference.com/w/cpp/types/numeric_limits/digits

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.