Discussion about integer overflow

No, I left it out deliberately. I don’t find it particularly interesting what type you get from literals, you could as easily have received it as a function argument, read it from a file, or obtained it from a large array which someone behind your back had optimized the storage of.

My point is that there are traps out there if you are unwary and that it isn’t something specific to Julia. In fact I find the satiating integer arithmetic of Matlab and Octave rather more insidious than the wraparound of Julia. It’s about as likely to give an incorrect result but a higher risk that you don’t notice.

Not only integers are tricky. Floating point numbers of course have their own quirks, such as this classic:

octave:1> mean(single(1.2 * ones(10000000, 1)))
ans =  1.0797

This is not at all theoretic; you can easily run into this when working with images. And yes, this can happen also in Julia even if the mean function itself does a better job. You simply have to know and understand your tools.

11 Likes