I need to read some numbers from a file and then do things with them. In theory I may get numbers that are bigger than 2^{128} so I parse them as BigInt. However, usually they are smaller than 2^{63} so Int64 is enough.
My “solution” was to parse them as BigInt and then demote them to Int64 if they are not too big. Then I can create my structure and go do my thing. The problem with this is that parse does not want to change BigInt to Int64. This is reasonable since it will usually fail, but in this case it won’t. Is there any way to do that or I have to parse them as Int64 and start catching errors?
I just realised that the easiest fix is to parse them twice. I can parse them once as BigInt, check how big they are and parse them again with the correct type.