Le jeudi 03 décembre 2015 à 05:30 -0800, Stephan Buchert a écrit :
> Is there a good reason for this?
> 
>               _
>    _       _ _(_)_     |  A fresh approach to technical computing
>   (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
>    _ _   _| |_  __ _   |  Type "?help" for help.
>   | | | | | | |/ _` |  |
>   | | |_| | | | (_| |  |  Version 0.4.1 (2015-11-08 10:33 UTC)
>  _/ |\__'_|_|_|\__'_|  |  
> |__/                   |  x86_64-redhat-linux
> 
> julia> Int32(5730)*86400000
> 495072000000
> 
> julia> Int32[5730]*86400000
> ERROR: InexactError()
>  in .* at arraymath.jl:127
>  in * at abstractarraymath.jl:55
> 
> julia> 
Yes. Though the difference is hard to get at first, it comes from the
fact that the result doesn't fit in an Int32. Indeed, multiplication of
an Int32 by and Int64 gives an Int64 (first command). In your second
command, that Int64 value has to be stored in the Int32 array, which
would incur an overflow. You can get the same error with this:
julia> Int32(5730*86400000)
ERROR: InexactError()
 in call at ./essentials.jl:58
 in eval at ./boot.jl:263

If you really want the overflowing behavior, you can write this:
julia> Int32[5730]*Int32(86400000)
1-element Array{Int32,1}:
 1150760960

This works since Int32 * Int32 gives back an Int32, without overflow
checks (but you probably don't want this...).


Regards

Reply via email to