Reputation: 324
In my answer to the question here: https://math.stackexchange.com/questions/2093497/finding-number-of-coprime-tuples-from-1-to-n/2094773#2094773 on Math SE, I am currently getting a runtime error on the line:
P=599*601
Error message is runtime error 6 overflow
P is defined as a Public variable of type double. I also have used p in my "modulo" function, defined as a double.
Why is this happening, and what can I do to correct it?
I have found a workaround: If I change the stated line to have instead:
P=359999
Then the error does not occur. Hence why does the line P=599*601 give an error?
Upvotes: 0
Views: 1988
Reputation: 324
After research, I found that this quirk can be solved via the following code:
Dim Prime1 as Long
Dim Prime2 as Long
Public P as Long
...
P=Prime1 * Prime2
Cause of the problem is likely due to assignment of integer type to p due to numbers when multiplied being integers.
Upvotes: 0