Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining '999e999' value without using char type in C++

Tags:

c++

Is it possible to define 999e999 value without using the char type?

I've tried defining it even with unsigned long long, but the compiler keeps giving me constant too big error.

Thanks in advance.

like image 698
hypnokat Avatar asked Jan 28 '23 04:01

hypnokat


2 Answers

Is it possible to define 999e999 value without using the char type?

No, that's not possible using intrinsic c++ data types. That's a way to big number that could be held in either a unsigned long long type in c++.

A long double type would enable you to use 10 based exponents as large as you want, for modern FPU architectures.

What can be achieved with your current CPU architecture can be explored using the std::numeric_limits facilities like this:

#include <iostream>
#include <limits>

int main() {   
   std::cout<< "max_exponent10: " << std::numeric_limits<long double>::max_exponent10  << std::endl;
}

Output:

max_exponent10: 4932

See the online demo

You have to use a 3rd party library (like GMP) or write your own algorithms to deal with big numbers like that.

like image 122
πάντα ῥεῖ Avatar answered Feb 04 '23 03:02

πάντα ῥεῖ


In most (If not all) implementations, that constant is just too big to be represented as a unsigned long long or long double (Though some may just have it be floating point infinity).

You may instead be interested in std::numeric_limits<T>::infinity() (for float, double or long double) or std::numeric_limits<T>::max() instead.

like image 42
Artyer Avatar answered Feb 04 '23 03:02

Artyer