I would like to use larger numbers than an unsigned long long in Arduino. Is that possible?
-
1You should look up the BigNumber library see if it is suitable for your needs.Majenko– Majenko2015年12月04日 09:39:04 +00:00Commented Dec 4, 2015 at 9:39
-
But... why do you need them? Usually when someone needs larger numbers then he has probably chosen the wrong algorithm...frarugi87– frarugi872015年12月04日 11:11:14 +00:00Commented Dec 4, 2015 at 11:11
-
I'll check it out.Andreas– Andreas2015年12月04日 11:56:15 +00:00Commented Dec 4, 2015 at 11:56
-
The entire point of my project is working with large numbers.Andreas– Andreas2015年12月04日 11:56:39 +00:00Commented Dec 4, 2015 at 11:56
1 Answer 1
There are many ways to use numbers bigger than an unsigned long
on Arduino. The right one depends on the application.
Floats and Doubles
float
s and double
s types on Arduino can hold exact integers up 2^53
. That is a very large number. They are built into the Arduino compiler.
uint64_t
The uint64_t
type can hold exact integers up to 2^64
. That is a very large number. This type is built into the Arduino compiler, but note that some Arduino library functions do not have versions for this type so may need to down-convert for printing and serializing and stuff like that.
BigNumber (or bc)
The BigNumber
type can represent exact numbers (integer or otherwise) limited only by available memory- but certainly hundreds of digits long on Arduino. These are extremely big numbers. This type is not built into the Arduino, but there is a nice Arduino library version available...
https://github.com/nickgammon/BigNumber
Again, this type is not supprted by the Arduino built-in library functions so you will need to either down-convert or find BigNumber
compatible functions for things like printing and serializing.