I have some very simple C++ code:
#include "stdafx.h"
#include "math.h"
int main(int argc, char* argv[])
{
long double i,t,c;
i = 16;
t = 27;
c = powl(i, t);
printf ("%f", c );
printf ("\n");
return 0;
}
According to Microsoft's calculation in Windows, 16^27 is:
3.2451855365842672678315602057626e+32
According to C++ it is:
324518553658426730000000000000000.000000
Why is this difference in precision happening? It must be completely precise, I am trying to make something simple that will encrypt a message in RSA"
Cipher text = Message **_^ E_** Mod N
If the exponent isn't computed precisely, it will come out incorrect.
Is there anything else that I could define that would be completely precise and hold that large of a number? If someone could direct me towards a class that would do precise math such as this it would be greatly appreciated.
-
0This is a long double (which is the same as double in Win32) and only has about 15 digits of precision. — stalk
-
0"Completely" precise? Of course not. And if you want higher amounts of precision, you'll need a specialized class that implements floating-point arithmetic manually. There are probably some free libraries lying around; maybe GMP includes floating point routines that you can use. — Mas Sehguh