So the question is:
Given a native integral type that represents the largest possible number in a given compiler (language?), for example ulong in C#, how do you detect that an input string representing a number is going to overflow the largest value that is representable by that given type without falling back to a checked context and a runtime OveflowException?
Obviously the C# compiler can detect constant integral overflows:
ulong l = 18446744073709551615; //ok
ulong l = 18446744073709551616; //compile time error: Integral constant is too large.
Is the compiler using a runtime OverflowException (or equivalent) under the hood? If so, is there a way to actually do this without recurring to a runtime exception or building a numeric type that can hold larger numbers like System.Numeric.BigInt? It is worth noting that BigInt has no native support in C# as the following is a compile time error although the integral constant is well inside the type's range:
BigInt i = 18446744073709551616; //compile time error: Integral constant is too large.
TryParsealso count as a no-no?UInt64.TryParse, there is notry-catchon the road. However, i don't know the way the compiler actually uses.uncheckedcontext and make hardware-like overflow detection, but not sure that's better than exceptions.Uint64.TryParsewas not correct, here is what i originally wanted to link: referencesource.microsoft.com/#mscorlib/system/…