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









up vote
4
down vote

favorite












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.










share|improve this question

















  • 2




    You may be interested in GMP.
    – Jesper Juhl
    Nov 11 at 18:48






  • 2




    Yes that's the way to go hypnokat, just like @JesperJuhl mentioned. However, I suggest you make sure first that you really need to use that big numbers!
    – gsamaras
    Nov 11 at 18:52






  • 1




    based on what you want to do with your number, you may be able to use openssl BN functions too.
    – Afshin
    Nov 11 at 19:15






  • 1




    Out of curiosity, why would one ever need such a big number? Even if you think that every particle in the universe is itself a universe with the same number of particles, you'll have about 10^172 particles in total. Even if you wanted to count the number of particles that can fit in these universes "space", that number would still be huge! Do you need unit precision on such a... supercalifragilistic number?
    – L.C.
    Nov 11 at 19:28










  • It is just a random experiment I thought of, I'm a programming newbie. Still, thanks to that random thought, even thought I can't do that in C++ alone, I now know about the existance of GMP, so I'm still walking out with something new :)
    – hypnokat
    Nov 11 at 19:35














up vote
4
down vote

favorite












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.










share|improve this question

















  • 2




    You may be interested in GMP.
    – Jesper Juhl
    Nov 11 at 18:48






  • 2




    Yes that's the way to go hypnokat, just like @JesperJuhl mentioned. However, I suggest you make sure first that you really need to use that big numbers!
    – gsamaras
    Nov 11 at 18:52






  • 1




    based on what you want to do with your number, you may be able to use openssl BN functions too.
    – Afshin
    Nov 11 at 19:15






  • 1




    Out of curiosity, why would one ever need such a big number? Even if you think that every particle in the universe is itself a universe with the same number of particles, you'll have about 10^172 particles in total. Even if you wanted to count the number of particles that can fit in these universes "space", that number would still be huge! Do you need unit precision on such a... supercalifragilistic number?
    – L.C.
    Nov 11 at 19:28










  • It is just a random experiment I thought of, I'm a programming newbie. Still, thanks to that random thought, even thought I can't do that in C++ alone, I now know about the existance of GMP, so I'm still walking out with something new :)
    – hypnokat
    Nov 11 at 19:35












up vote
4
down vote

favorite









up vote
4
down vote

favorite











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.










share|improve this question













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.







c++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 18:45









hypnokat

254




254







  • 2




    You may be interested in GMP.
    – Jesper Juhl
    Nov 11 at 18:48






  • 2




    Yes that's the way to go hypnokat, just like @JesperJuhl mentioned. However, I suggest you make sure first that you really need to use that big numbers!
    – gsamaras
    Nov 11 at 18:52






  • 1




    based on what you want to do with your number, you may be able to use openssl BN functions too.
    – Afshin
    Nov 11 at 19:15






  • 1




    Out of curiosity, why would one ever need such a big number? Even if you think that every particle in the universe is itself a universe with the same number of particles, you'll have about 10^172 particles in total. Even if you wanted to count the number of particles that can fit in these universes "space", that number would still be huge! Do you need unit precision on such a... supercalifragilistic number?
    – L.C.
    Nov 11 at 19:28










  • It is just a random experiment I thought of, I'm a programming newbie. Still, thanks to that random thought, even thought I can't do that in C++ alone, I now know about the existance of GMP, so I'm still walking out with something new :)
    – hypnokat
    Nov 11 at 19:35












  • 2




    You may be interested in GMP.
    – Jesper Juhl
    Nov 11 at 18:48






  • 2




    Yes that's the way to go hypnokat, just like @JesperJuhl mentioned. However, I suggest you make sure first that you really need to use that big numbers!
    – gsamaras
    Nov 11 at 18:52






  • 1




    based on what you want to do with your number, you may be able to use openssl BN functions too.
    – Afshin
    Nov 11 at 19:15






  • 1




    Out of curiosity, why would one ever need such a big number? Even if you think that every particle in the universe is itself a universe with the same number of particles, you'll have about 10^172 particles in total. Even if you wanted to count the number of particles that can fit in these universes "space", that number would still be huge! Do you need unit precision on such a... supercalifragilistic number?
    – L.C.
    Nov 11 at 19:28










  • It is just a random experiment I thought of, I'm a programming newbie. Still, thanks to that random thought, even thought I can't do that in C++ alone, I now know about the existance of GMP, so I'm still walking out with something new :)
    – hypnokat
    Nov 11 at 19:35







2




2




You may be interested in GMP.
– Jesper Juhl
Nov 11 at 18:48




You may be interested in GMP.
– Jesper Juhl
Nov 11 at 18:48




2




2




Yes that's the way to go hypnokat, just like @JesperJuhl mentioned. However, I suggest you make sure first that you really need to use that big numbers!
– gsamaras
Nov 11 at 18:52




Yes that's the way to go hypnokat, just like @JesperJuhl mentioned. However, I suggest you make sure first that you really need to use that big numbers!
– gsamaras
Nov 11 at 18:52




1




1




based on what you want to do with your number, you may be able to use openssl BN functions too.
– Afshin
Nov 11 at 19:15




based on what you want to do with your number, you may be able to use openssl BN functions too.
– Afshin
Nov 11 at 19:15




1




1




Out of curiosity, why would one ever need such a big number? Even if you think that every particle in the universe is itself a universe with the same number of particles, you'll have about 10^172 particles in total. Even if you wanted to count the number of particles that can fit in these universes "space", that number would still be huge! Do you need unit precision on such a... supercalifragilistic number?
– L.C.
Nov 11 at 19:28




Out of curiosity, why would one ever need such a big number? Even if you think that every particle in the universe is itself a universe with the same number of particles, you'll have about 10^172 particles in total. Even if you wanted to count the number of particles that can fit in these universes "space", that number would still be huge! Do you need unit precision on such a... supercalifragilistic number?
– L.C.
Nov 11 at 19:28












It is just a random experiment I thought of, I'm a programming newbie. Still, thanks to that random thought, even thought I can't do that in C++ alone, I now know about the existance of GMP, so I'm still walking out with something new :)
– hypnokat
Nov 11 at 19:35




It is just a random experiment I thought of, I'm a programming newbie. Still, thanks to that random thought, even thought I can't do that in C++ alone, I now know about the existance of GMP, so I'm still walking out with something new :)
– hypnokat
Nov 11 at 19:35












3 Answers
3






active

oldest

votes

















up vote
4
down vote



accepted











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.






share|improve this answer


















  • 1




    Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
    – geza
    Nov 11 at 19:20










  • On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
    – geza
    Nov 11 at 19:24










  • @geza Reference please (including support from c++ standards)?
    – πάντα ῥεῖ
    Nov 11 at 19:26











  • What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
    – geza
    Nov 11 at 19:36











  • @geza M'kay. I probably should refine my answer.
    – πάντα ῥεῖ
    Nov 11 at 19:44

















up vote
2
down vote













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.






share|improve this answer




















  • I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
    – hypnokat
    Nov 11 at 19:46







  • 1




    @hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
    – Artyer
    Nov 11 at 20:03

















up vote
2
down vote














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




Of course it does. A long long is typically 64 bits long, which gives you log(2^64) ≅ 19 decimal digits of precision. 999e999 ≅ (10^3)^1000, so is on the order of 3000 decimal digits long, or nearly 10,000 bits long. So 999e999 isn't just too big for a long long, it's too big by an enormous margin.




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




Sure. You could define an integer-like type based on an array of some sort of integers, like long long. You'd still need to write a set of operators to work with your new giant type, though. Also, most of the time when you're working with numbers that large, you don't need an exact representation, which is why floating point types like float and double are useful.






share|improve this answer




















  • Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
    – hypnokat
    Nov 11 at 19:43






  • 1




    Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
    – Caleb
    Nov 11 at 20:19










  • @SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
    – Caleb
    Nov 11 at 21:27










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251991%2fdefining-999e999-value-without-using-char-type-in-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted











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.






share|improve this answer


















  • 1




    Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
    – geza
    Nov 11 at 19:20










  • On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
    – geza
    Nov 11 at 19:24










  • @geza Reference please (including support from c++ standards)?
    – πάντα ῥεῖ
    Nov 11 at 19:26











  • What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
    – geza
    Nov 11 at 19:36











  • @geza M'kay. I probably should refine my answer.
    – πάντα ῥεῖ
    Nov 11 at 19:44














up vote
4
down vote



accepted











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.






share|improve this answer


















  • 1




    Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
    – geza
    Nov 11 at 19:20










  • On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
    – geza
    Nov 11 at 19:24










  • @geza Reference please (including support from c++ standards)?
    – πάντα ῥεῖ
    Nov 11 at 19:26











  • What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
    – geza
    Nov 11 at 19:36











  • @geza M'kay. I probably should refine my answer.
    – πάντα ῥεῖ
    Nov 11 at 19:44












up vote
4
down vote



accepted







up vote
4
down vote



accepted







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 19:50

























answered Nov 11 at 18:49









πάντα ῥεῖ

71.4k972134




71.4k972134







  • 1




    Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
    – geza
    Nov 11 at 19:20










  • On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
    – geza
    Nov 11 at 19:24










  • @geza Reference please (including support from c++ standards)?
    – πάντα ῥεῖ
    Nov 11 at 19:26











  • What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
    – geza
    Nov 11 at 19:36











  • @geza M'kay. I probably should refine my answer.
    – πάντα ῥεῖ
    Nov 11 at 19:44












  • 1




    Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
    – geza
    Nov 11 at 19:20










  • On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
    – geza
    Nov 11 at 19:24










  • @geza Reference please (including support from c++ standards)?
    – πάντα ῥεῖ
    Nov 11 at 19:26











  • What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
    – geza
    Nov 11 at 19:36











  • @geza M'kay. I probably should refine my answer.
    – πάντα ῥεῖ
    Nov 11 at 19:44







1




1




Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
– geza
Nov 11 at 19:20




Actually, where long double has a bigger size than the usual 8-byte double (like 80-bit on x86), long double can store 999e999.
– geza
Nov 11 at 19:20












On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
– geza
Nov 11 at 19:24




On x86, FPU supports 80-bit numbers. And it is usually accessible by using long double. This type still can be used today on x86_64 as well.
– geza
Nov 11 at 19:24












@geza Reference please (including support from c++ standards)?
– πάντα ῥεῖ
Nov 11 at 19:26





@geza Reference please (including support from c++ standards)?
– πάντα ῥεῖ
Nov 11 at 19:26













What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
– geza
Nov 11 at 19:36





What do you mean by support from C++ standards? C++ standard doesn't say too much about the range of floating point. It doesn't change the fact, that on x86, the FPU (i387) can use 80-bit numbers. With GCC/Clang, this is definitely accessible by using long double. See: godbolt.org/z/e0HD_T (TBYTE means a 10-byte type)
– geza
Nov 11 at 19:36













@geza M'kay. I probably should refine my answer.
– πάντα ῥεῖ
Nov 11 at 19:44




@geza M'kay. I probably should refine my answer.
– πάντα ῥεῖ
Nov 11 at 19:44












up vote
2
down vote













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.






share|improve this answer




















  • I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
    – hypnokat
    Nov 11 at 19:46







  • 1




    @hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
    – Artyer
    Nov 11 at 20:03














up vote
2
down vote













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.






share|improve this answer




















  • I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
    – hypnokat
    Nov 11 at 19:46







  • 1




    @hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
    – Artyer
    Nov 11 at 20:03












up vote
2
down vote










up vote
2
down vote









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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 19:06









Artyer

3,738625




3,738625











  • I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
    – hypnokat
    Nov 11 at 19:46







  • 1




    @hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
    – Artyer
    Nov 11 at 20:03
















  • I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
    – hypnokat
    Nov 11 at 19:46







  • 1




    @hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
    – Artyer
    Nov 11 at 20:03















I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
– hypnokat
Nov 11 at 19:46





I've looked through your example, but if I read it correctly then maximum value for std::numeric_limits<T>::max() is 1.79769e+308, which is a lot less than 999e999, so I'm afraid I wouldn't be able to use it. Even so, could I use std::numeric_limits<T>::infinity() to extract a value other than infinity?
– hypnokat
Nov 11 at 19:46





1




1




@hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
– Artyer
Nov 11 at 20:03




@hypnokat It boils down to how floats are implemented in the system. The most common implementation has a largest value (Which is what max returns) and an inf value (Which is what infinity returns). These, again, depend on how the float types are implemented.
– Artyer
Nov 11 at 20:03










up vote
2
down vote














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




Of course it does. A long long is typically 64 bits long, which gives you log(2^64) ≅ 19 decimal digits of precision. 999e999 ≅ (10^3)^1000, so is on the order of 3000 decimal digits long, or nearly 10,000 bits long. So 999e999 isn't just too big for a long long, it's too big by an enormous margin.




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




Sure. You could define an integer-like type based on an array of some sort of integers, like long long. You'd still need to write a set of operators to work with your new giant type, though. Also, most of the time when you're working with numbers that large, you don't need an exact representation, which is why floating point types like float and double are useful.






share|improve this answer




















  • Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
    – hypnokat
    Nov 11 at 19:43






  • 1




    Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
    – Caleb
    Nov 11 at 20:19










  • @SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
    – Caleb
    Nov 11 at 21:27














up vote
2
down vote














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




Of course it does. A long long is typically 64 bits long, which gives you log(2^64) ≅ 19 decimal digits of precision. 999e999 ≅ (10^3)^1000, so is on the order of 3000 decimal digits long, or nearly 10,000 bits long. So 999e999 isn't just too big for a long long, it's too big by an enormous margin.




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




Sure. You could define an integer-like type based on an array of some sort of integers, like long long. You'd still need to write a set of operators to work with your new giant type, though. Also, most of the time when you're working with numbers that large, you don't need an exact representation, which is why floating point types like float and double are useful.






share|improve this answer




















  • Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
    – hypnokat
    Nov 11 at 19:43






  • 1




    Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
    – Caleb
    Nov 11 at 20:19










  • @SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
    – Caleb
    Nov 11 at 21:27












up vote
2
down vote










up vote
2
down vote










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




Of course it does. A long long is typically 64 bits long, which gives you log(2^64) ≅ 19 decimal digits of precision. 999e999 ≅ (10^3)^1000, so is on the order of 3000 decimal digits long, or nearly 10,000 bits long. So 999e999 isn't just too big for a long long, it's too big by an enormous margin.




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




Sure. You could define an integer-like type based on an array of some sort of integers, like long long. You'd still need to write a set of operators to work with your new giant type, though. Also, most of the time when you're working with numbers that large, you don't need an exact representation, which is why floating point types like float and double are useful.






share|improve this answer













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




Of course it does. A long long is typically 64 bits long, which gives you log(2^64) ≅ 19 decimal digits of precision. 999e999 ≅ (10^3)^1000, so is on the order of 3000 decimal digits long, or nearly 10,000 bits long. So 999e999 isn't just too big for a long long, it's too big by an enormous margin.




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




Sure. You could define an integer-like type based on an array of some sort of integers, like long long. You'd still need to write a set of operators to work with your new giant type, though. Also, most of the time when you're working with numbers that large, you don't need an exact representation, which is why floating point types like float and double are useful.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 19:09









Caleb

108k16149238




108k16149238











  • Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
    – hypnokat
    Nov 11 at 19:43






  • 1




    Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
    – Caleb
    Nov 11 at 20:19










  • @SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
    – Caleb
    Nov 11 at 21:27
















  • Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
    – hypnokat
    Nov 11 at 19:43






  • 1




    Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
    – Caleb
    Nov 11 at 20:19










  • @SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
    – Caleb
    Nov 11 at 21:27















Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
– hypnokat
Nov 11 at 19:43




Sorry if I'm asking obvious stuff, but by defining an integer-like type do you mean I could use typedef? If so then how do I write my own operators from that point on?
– hypnokat
Nov 11 at 19:43




1




1




Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
– Caleb
Nov 11 at 20:19




Sure, you could define a type like typedef long[350] ReallyBigNumber; and then define a bunch of functions that add, subtract, multiply, etc. values of that type. If you're working in C++, you might want to create ReallyBigNumber as a class, and then you can overload operator+, operator-, etc. so that you can use normal math operators like + and -. But it'd be a little silly to do all that when arbitrary precision libraries like GMP already exist.
– Caleb
Nov 11 at 20:19












@SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
– Caleb
Nov 11 at 21:27




@SolomonSlow You're right: 999e999 is scientific notation, so should be interpreted as 999*10^999; I was thinking of 999^999, and I probably still didn't get it quite right. In a hurry just now, but will fix in a few hours.
– Caleb
Nov 11 at 21:27

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251991%2fdefining-999e999-value-without-using-char-type-in-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3