Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
113 views

Given something like the following: struct numeric_limits_max_t { template<class T> constexpr operator T() const noexcept { return std::numeric_limits<T>::max(); } }; ...
darune's user avatar
  • 11.5k
1 vote
1 answer
308 views

Following the discussion in c++ long double (128-bit) precision, what's the use case of numeric_limits<long double>::max()? How can I trust that constant, for example in checking for range / ...
khteh's user avatar
  • 4,280
4 votes
2 answers
212 views

I am designing some double-double and quad-double arithmetic libraries for C++11. Part of the code is based off of the QD and DDFUN library from https://www.davidhbailey.com/dhbsoftware/. struct ...
Vortex 2728182818's user avatar
2 votes
0 answers
80 views

I am learning how to clear an input buffer. So far I have come across two statements that both work and seem to do the same thing: while(getchar() != '\n'); cin.ignore(numberic_limits<streamsize&...
Lena_Bean's user avatar
0 votes
0 answers
160 views

I have a C++ class which gets instantiated a very large number of times. It has an unsigned short private member. I am getting very different runtime performance depending on whether I initialize it ...
Tuee's user avatar
  • 1
-1 votes
2 answers
127 views

I'm studying C++ using The C++ Programming Language from Bjarne Stroustrup, and while doing exercise 4.5 (What, on your system, are the largest and the smallest values of the following types: char, ...
Felipe Maion's user avatar
7 votes
2 answers
373 views

This code compiles and runs #include <limits> #include <iostream> struct Foo { int x; }; static_assert(!std::numeric_limits<Foo>::is_specialized); int main() { std::cout &...
Enlico's user avatar
  • 30.3k
-3 votes
2 answers
90 views

I came accross the following in a C++ textbook: bool result3 = numeric_limits<double>::is_signed; //result3 holds a value of true bool result4 = numeric_limits<short>::is_integer; ...
Lena_Bean's user avatar
0 votes
0 answers
113 views

I am trying to convert floating point values to their string representation, using the QString class from the Qt framework. To do this, I am using the following function: QString QString::arg(double a)...
HarryP2023's user avatar
0 votes
2 answers
164 views

I'm facing a little problem on a personal project: When I'm converting a float number to a double to make operations (+-*/) easy, it adds a lot of 0s behind the default float number. For example: ...
Lewisuehjo's user avatar
2 votes
1 answer
3k views

I recently learnt that: The correct way to get the largest possible value of a numeric type on your system is to use std::numeric_limits. In particular, we can use std::numeric_limits<unsigned int&...
Julian's user avatar
  • 63
3 votes
0 answers
31 views

std::numeric_limits<T>::infinity() function is logically misbehaving for integral types but for double its working fine. Is there some reason for defining such behavior in standard library, ...
virus00x's user avatar
  • 751
-2 votes
2 answers
802 views

Assuming there is a declaration in a header file you don't control that states something like: static const uint16 MaxValue = 0xffff; // the type could be anything, static or not Inside a file that ...
PRouleau's user avatar
  • 234
-2 votes
1 answer
1k views

Why is the concept std::integral defined as template < class T > concept integral = std::is_integral_v<T>; and not as template < class T > concept integral = std::numeric_limits<...
Helmut Zeisel's user avatar
1 vote
1 answer
701 views

I have code like this: // .h file #include <iostream> #include <limits> class MyClass { public: myInput(); int inputValue; } // .cpp file #include "MyClass.h" void ...
Mavimix's user avatar
  • 179
2 votes
2 answers
114 views

I'm a beginner with C++ so this may seem like a silly question. Please humour me! I was using static_cast<int>(numeric_limits<unsigned_char>::min()) and ::max() (according to this post), ...
AlexaGIS's user avatar
1 vote
1 answer
45 views

In stanza, I would like to get the numeric limits (min and max) of Int and Double types. In C++, there are INT_MIN, INT_MAX, DBL_MIN and DBL_MAX.
Bertrand Pellenard's user avatar
1 vote
3 answers
283 views

When I run this code: double getRandomDouble() { static std::mt19937 entropy_ = std::mt19937(); std::uniform_real_distribution<double> distribution; distribution.param(typename ...
Troyseph's user avatar
  • 5,138
0 votes
2 answers
343 views

So I figure I'll put this here since I had to traverse a lot of docs and forums to find the definitive answer. I was trying to get input from the user and check if the input was an integer using ...
CrypticEthos's user avatar
2 votes
1 answer
209 views

I have a function that takes in an optional distance parameter dist, but my algorithm works with squared distances. If the user does not specify any value, I want dist to be as large a number as ...
Touloudou's user avatar
  • 2,293
0 votes
1 answer
472 views

numeric_limits<double>::epsilon() is defined to be the difference between 1.0 and the next value representable by double, but I want to find/calculate the numeric_limits<double>::epsilon() ...
Tomer Wolberg's user avatar
3 votes
3 answers
12k views

I recently noticed numeric_limits::max() and numeric_limits::min() don't seem to work for uint8_t and int8_t. Is there a reason for this or could it be a bug? I tried on my own computer using gcc ...
Paradox's user avatar
  • 2,045
10 votes
3 answers
957 views

Fair and simple: How do I check if anything else but an integer is passed to my class in c++? If I pass f.e. a char 'a' my class gets number 97 in ascii. I tried std::numeric_limits but I don't get ...
Ingo Mi's user avatar
  • 1,109
1 vote
1 answer
121 views

Suppose I am using float to hold integer values and adding small shifts to it, approximately 1s or 2s. At which value float will stop to change? What is the name of this value?
Dims's user avatar
  • 51.8k
0 votes
1 answer
199 views

I naively tried template<typename T> void foo(T a, T b){ if(min==max){ max += std::numeric_limits<T>::epsilon(); } // Do some other stuff } However I found out that epsilon ...
bradgonesurfing's user avatar
4 votes
2 answers
195 views

I am trying to convert numeric types to fixed length string representations with leading '0's (used in a GUI that can only deal with strings - and lexicographic sorting of numbers is really awkward). ...
ABaumstumpf's user avatar
4 votes
1 answer
301 views

The following code: template <typename T, typename U> typename std::enable_if< std::numeric_limits<T>::max() == std::numeric_limits<U>::max(), bool>::type same_max() { ...
Boris Dalstein's user avatar
1 vote
2 answers
2k views

Using Visual Studio Community 2019 v16.4.2 with the latest stuff it comes with on 64bit Win10. While testing various datatype limits ran into a weird bug, numeric_limits can't distinguish between ...
deVoid's user avatar
  • 13
4 votes
3 answers
104 views

Given a variable defined as T x; where T is a generic arithmetic type (i.e. such that std::is_arithmetic<T>::value), is there a simple expression (e.g something from std::numeric_limits) that ...
Museful's user avatar
  • 7,019
2 votes
3 answers
286 views

I was supposing that numeric_limits::max() on a BOOST_STRONG_TYPEDEF defined type would give the same result than on the underlying type. But the following program shows that it is not the case (...
Kleag's user avatar
  • 670
2 votes
1 answer
269 views

I try to implement a meta function which checks if an integer type is a subset of another integer type. It should be platform independent and work at least with all numeric types defined by the C++ ...
Martin Fehrs's user avatar
  • 1,175
2 votes
0 answers
189 views

The following program apparently shows an inconsistency when writing and reading on a std::stringstream a double set to "infinity", using std::numeric_limits<double>::infinity. #include <...
francesco's user avatar
  • 7,617
12 votes
2 answers
1k views

I'm trying to write a test case for some corner case. For input of type int64_t, the following line won't compile: int64_t a = -9223372036854775808LL; The error/warning is: error: integer constant ...
fluter's user avatar
  • 14k
1 vote
1 answer
2k views

With GCC 9.1, when calling std::numeric_limits's functions with floating-point types, they return 0 in most cases. This happens in a project I'm working on, and there is no issue with MSVC, GCC 8.3 ...
Razakhel's user avatar
  • 772
3 votes
2 answers
227 views

In C++11, what is the advantage of std::numeric_limits<Type>::max_digits10 returning 0 for a Type that is a reference to floating point number? For example: constexpr int precisionPositive(...
WilliamKF's user avatar
  • 43.6k
1 vote
2 answers
5k views

While using cin.ignore() in c++, it takes an argument of number of characters to consume until the delimiter occurs. Most often I have observed the following to be used cin.ignore(numeric_limits<...
Shubham Yadav's user avatar
6 votes
1 answer
1k views

If you mistakenly do something like: #include<limits> int arr[3]; auto x = std::numeric_limits<decltype(arr[0])>::max(); You will get unhelpful error message from the file in the STL ...
NoSenseEtAl's user avatar
  • 30.9k
5 votes
2 answers
579 views

IEEE floating point exponents are stored as unsigned integers, using a pre-defined exponent bias to offset the exponent. The exponent bias seems to be consistently equal to numeric_limits<T>::...
Jonathan Mee's user avatar
  • 39.1k
1 vote
1 answer
5k views

I would like to know if there is a particular reason to define the macro UINT_MAX as (2147483647 * 2U + 1U) and not directly its true value (4294967295U) in the climits header file. Thank you all.
ThunderPhoenix's user avatar
0 votes
1 answer
4k views

I would like my code to only input integers. The code below does it's job correctly and asks the user for input if an integer was not used. However, after adding the code: while ( ! ( cin >> x )...
sabby_'s user avatar
  • 1
-4 votes
1 answer
555 views

in C++, I wonder how to get the correct answer 0.5 for "INT_MAX / (INT_MAX + INT_MAX)"? I tried cast the divisor/both divisor and dividend to long, and also cast divisor to double, all return -...
Eric Wong's user avatar
-1 votes
2 answers
224 views

I am under the impression that INT_MAX will turn on all 32 bits of an int. If I negate that and 'and' it with itself, I should be comparing all 0s with all 1s and get back false. What am I missing? ...
presence's user avatar
6 votes
1 answer
243 views

std::numeric_limits provides 2 constants that are mutually exclusive: is_integer : "true for all integer arithmetic types T" is_exact: "true for all arithmetic types T that use exact representation" ...
Jonathan Mee's user avatar
  • 39.1k
10 votes
2 answers
21k views

unsigned int updateStandardStopping(unsigned int numInliers, unsigned int totPoints, unsigned int sampleSize) { double max_hypotheses_=85000; double n_inliers = 1.0; double ...
Finley's user avatar
  • 865
20 votes
1 answer
4k views

I have created my own type, without any comparator, and without a specialization of std::numeric_limits. Despite that, for some reason, std::numeric_limits<MyType> compiles fine. Why did the c++ ...
tohava's user avatar
  • 5,422
0 votes
2 answers
320 views

Suppose someAtomic is an std::atomic with an integral underlying type, such as atomic_uint16_t. I don't want to assume WHICH integral type, however, in particular code, so I want something to ...
Display Name's user avatar
  • 2,423
0 votes
0 answers
747 views

Is numeric_limits::max() preferred over INT_MAX in C++ ? If so, what is the reason for this ? What should be preferred in simple cases like finding minimum and maximum element in an array ?
zk9099's user avatar
  • 183
5 votes
1 answer
5k views

Limits is the header file in c++ which consists of numeric_limits class whereas climits is the header file consisting of the min and max values of various data types only. Limits can be used ...
Mukul Baheti's user avatar
-1 votes
3 answers
582 views

So far, this is my code: while(bet > remaining_money || bet < 100) { cout << "You may not bet lower than 100 or more than your current money. Characters are not accepted." <...
user avatar
0 votes
1 answer
2k views

I have a function which is given a buffer which accepts to be filled up to a size_t length; however, the actual call which fills it wants an int as max length. So, in case the parameter cannot fit ...
Francesco Dondi's user avatar