I really agree that this is a mistake that is easily made. There is a FAQ
answer<http://docs.julialang.org/en/latest/manual/faq/#why-does-julia-use-native-machine-integer-arithmetic>
that
explains why we use integer arithmetic with silent overflow.
I think Julia would benefit from a simpler way to express numerical
constants with type than to first create a Float64 / Int32/64 and then send
to constructor, but I have not (yet) found a syntax to suggest that would
get approval.
One idea might be to implement a @big macro that would allow you to write
@big(2^32)
and it would be automatically translated to
big(2)^big(32)
The problem is that it will not work (in a sensible way) for floating
point, because the macro will not be able to see the string representation,
but the closest Float64 version. This means that 0.1 will
be 1.000000000000000055511151231257827021181583404541015625e-01 instead
of
1.000000000000000000000000000000000000000000000000000000000000000000000000000002e-01
kl. 17:02:25 UTC+1 søndag 12. januar 2014 skrev Földes László følgende:
>
> This little piece of code tricked me:
>
> if value < big(2^32)
> println("Finished!")
> break
> end
>
> The println was never executed and couldn't find the problem for about 3
> minutes when I tried it on a 64 bit OS, where it worked.
> The problem is that on 32-bit OS 2^32 equals to zero. I'm just getting
> used to Julia internals and it is not really a problem if it is apparent,
> but I clearly need more time with the language to spot these kind of error.
>
> if value < big(2)^big(32)
> println("Finished!")
> break
> end
> solve this. But this is ugly and it looks like something that can be
> automated.
>
> is there any coding style that can prevent this error? I would better
> receive an overflow error (if it is turned on with a flag to the Julia
> executable maybe) than a silent, never running piece of code.
>