Win32 bit versus Win64 bit Julia


My code is working on Win64 Bit Julia but not on Win32 Bit Julia. It is giving TypeError:typeassert.
What would be the reason? A program is working on Win64 but not on Win32.



The typeassert should give you a clear message of what’s expected and what it get also a location where it happens. It’s impossible for anyone to help without more info.


If you assert anywhere in your code that some variable must be a Float64 or of type with Float64 parameter, it will probably give an error. Constants are taken by default to be Float32 or Int32 on 32 bit machines, and Float64 or Int64 on 64 bit machines. Int is Int64 in 64 bit machines and Int32 in 32 bit machines. For example my machine is 64 bit so the default for 1 is Int64(1).

julia> typeof(1)

julia> Int32(1)::Int
ERROR: TypeError: typeassert: expected Int64, got Int32

julia> Int

julia> Float32(1)::Float64
ERROR: TypeError: typeassert: expected Float64, got Float32

If that’s really the problem, you could define Float = typeof(1.) at the beginning of your program, and then replace Float64 everywhere in your program with Float.


This is incorrect. (I feel like it should be in the FAQ, since it comes up so often.)

32-bit machines have nothing to do with floating-point precision; this is a common misconception. 32-bit processors still have 64-bit (and wider!) floating-point registers, and floating-point literals like 1.0 are still Float64 in 32-bit Julia.

Integers (both literals and things like length(array)) are different: they default to type Int in Julia, which is Int64 on 64-bit machines and Int32 on 32-bit machines.


Close. Floating point numbers are the same on 32-bit architectures, so Float64 is fine. However, integers aren’t. So typeof(1) <: Int64 is false on a 32-bit machine. This means that if you do things like f(x::Int64), f(1) will error with a missing method on 32-bit machines.

Moral of the story: never write Int64 and always write Int. Int will always match the machine integer: typeof(1) <: Int is true on both 32-bit and 64-bit. Only use Int64 if you’ve explicitly up-converted to 64-bit integers. 99.99999% of problems that are “tests pass on 64-bit and not 32-bit” are because you wrote Int64 somewhere. Just find/replace Int64–>Int and you’ll likely be good. If that doesn’t work, then 32-bit is having an overflow error.


There is one important exception to that rule. If you want your code to work on both 32 and 64 bits and use JLD to store data, make sure to specify the integer widths within types you store. See