You're passing a UInt8 to f() which results in a mod of 0x0000000000000001,
from which 3 is subtracted resulting in 0xfffffffffffffffe return value.
Casting that to an Int, you get -2.
Try f(UInt8(4)) to see this in action.
In 0.4, your test_abs() example results in an InexactError.
On Saturday, September 5, 2015 at 7:31:35 PM UTC-7, Corey Moncure wrote:
>
> Can someone help me understand what's going on here?
> Maybe I've been sitting at my desk too long?
>
> julia> arr = hex2bytes("14fb9c03")
> 4-element Array{Uint8,1}:
> 0x14
> 0xfb
> 0x9c
> 0x03
>
> julia> f(x) = abs((x % 3) - 3)
> f (generic function with 1 method)
>
> julia> function test_abs(bytes_input::Array{Uint8})
> input_len::Uint = sizeof(bytes_input)
> a::Int = f(input_len)
> println("a: ", a, " input len: ", input_len)
> end
> test_abs (generic function with 1 method)
>
> julia> test_abs(arr)
> a: -2 input len: 4 <-- minus 2????
>
> julia> sizeof(arr)
> 4
>
> julia> f(4)
> 2 <-- expected
>
>
>
>
>