This is an area where I feel Julia is a bit inconsistent in it’s philosophy.
Unlike C/C++, by default, when accessing a string or an array, bounds are checked (i.e. safe by default), however using the
@inbounds macro, you can eliminate the bounds checking (basically 100% of the time in my programming I need to use that, because I check bounds at the top level, not on every access, for performance).
However, the opposite philosophy is used for numbers, operations do not check for overflow by default (and it’s a bit difficult to make that happen, there is no
@checkoverflow macro to make sure that happens generically).
I understand why they decided to do things this way (the fallout from going out of bounds is generally much worse than the fallout from overflowing an numeric operation), however it would be nice if there were a generic way (that people implementing custom numeric types could also support), to indicate that overflow checking is desired.
While that is true,
BigInt is quite slow, and take up a huge amount of memory compared to say
Int128, and so may work in some applications where speed / memory usage are important.
With v0.7, it might be possible to make a small
Union type, that was an
BigInt (or a better replacement for
BigInt), and operations which overflowed an
Int64 would return a