Reputation: 85
I need to work out if a massive integer (I mean 20 digits...) is prime.
I'm trying to use the brute-force method, but (of course) I need to use doubles to contain the original number. However, the modulo operator (%) is an integer operator - thus it is useless to me!
Upvotes: 0
Views: 716
Reputation: 59473
Since the double data type is stored as a fractional value scaled to some power of two, and since it only has a precision of 15 decimal digits, a 20-digit number stored as a double will always be divisible by two, and therefore, is not prime.
Upvotes: 3
Reputation:
Are you looking for fmod
in the C standard library? Or possibly fmodl
for long double
?
Upvotes: 1
Reputation: 941635
That's not possible, a double only has 15 significant digits. Look for an implementation of a BigInt class. C specific is discussed here.
Upvotes: 18