# Taking the square of a large number using BigNumber.h

All,

I am generally trying to convert the results from an I2C chip into the correct output. To do this I need to compute some fairly large numbers.

My starting point for now is 1072953^2, I found the library Bignumber.h, and while it seems great at calculating large numbers it seems I can only feed ints into the library.

`BigNumber a = 1072953;` returns 24377. I dug though the .h files for the library and it seems that I can only give the function ints;

``````// constructors
BigNumber ();  // default constructor
BigNumber (const char * s);   // constructor from string
BigNumber (const int n);  // constructor from int
// copy constructor
BigNumber (const BigNumber & rhs);
``````

How could I feed a larger number into the Bignumber.h?
Is there a better way to do this?
Does Bignumber.h have some real documentation, other then the examples and Gammon Forum : Electronics : Microprocessors : Arbitrary precision (big number) library port for Arduino ?

Austin.

Not to be contrary, but surprisingly often, people who think they need big numbers for a computation really don't... just saying.

You are very correct.

I tried a couple way, both by and and in MatLAB to simplify the equations to make this possible. This is how I got to the x^2 value. This seems to be as far as I can get with out the use of some large number code.

tex_downey:
You are very correct.

I tried a couple way, both by and and in MatLAB to simplify the equations to make this possible. This is how I got to the x^2 value. This seems to be as far as I can get with out the use of some large number code.

Well, I don't doubt that you need to square it. But do you really need the precision of the diameter of a pin vs. the distance between Jupiter and the Sun as a result?

My starting point for now is 1072953^2, I found the library Bignumber.h, and while it seems great at calculating large numbers it seems I can only feed ints into the library.

``````BigNumber a = 1072953;
``````

returns 24377.

Weird that there isn't a constructor for long arguments. How about:

``````BigNumber a = 811;
a = a * 1323;   /* 1072953 */
a = a * a;   /* squared */
``````

(only works in a code path, not as an initializer.) (I hope 1072953 wasn't supposed to be prime...)
You could use int64_t for this, but the last I heard, int64 support wasn't very good, so bignumber might even be better.

(did you know that older floating point formats had a magnitude limit of about 10^38, and you couldn't easily use those computers for physics homework involving "hBar squared"? I don't remember what the point of the physics was, but that HW was a real education in the limits of computers!)

Also, is this stand alone? If you are sending data to a PC, you have the use of fast 64 bit floating point.