I am making an algorithm that works with large numbers (up to 2^900), but a lot of operations are still not so large. And in this cases I would like to make normal maths instead of algorithms for large numbers. I have such part of code:
if (a * b < 1e17)
{
return(a * b);
}
else
{
//some large numbers maths
return(res);
}
And I am not sure whether it is a good way to check if the result fits in a Number variable. I know that some languages not always return something big, when they are out of stack. How does javascript do it? Will if (a * b < 1e17) always give false, when a*b is too big?
You asked to clarify the problem. Well, if it is not clear, I make exact question: will this part of code work correctly for each possible numbers a and b (if real result of multiplication is less then 1e17 it has to enter if statement and if not - enter else)? Will it always "go to" else if a and b are both more than 9 digits length?
if (a * b < 1e17)
{
return(a * b);
}
else
{
//some large numbers maths
return(res);
}