Int or Int64

508 views
Skip to first unread message

vincent leclere

unread,
Apr 13, 2016, 5:09:27 AM4/13/16
to julia-users
Hi all,

quick question: I am building a package and has been defining types with Int64 or Float64 properties.
Is there any reason why I should be using Int and Float instead ? (Does Int64 work on 32bits processors ?)
Will it be at the price of efficiency loss ?

Thanks

Bill Hart

unread,
Apr 13, 2016, 5:27:00 AM4/13/16
to julia-users
Int is either Int32 or Int64, depending on the machine. Int64 does still seem to be defined on a 32 bit machine. In fact, even Int128 is defined. But of course it is going to have to emulate processor instructions to do 64 bit arithmetic unless the machine actually has such instructions. So it could well be quite a bit slower.

Mauro

unread,
Apr 13, 2016, 8:10:21 AM4/13/16
to julia...@googlegroups.com
Also, note that floats work the same on both 32 and 64 bit machines (and
both default to making Float64). Concerning ints: use Int64 if you need
them for your code to be correct, otherwise use Int. (Maybe best to
just use Int64 to be on the save side?)

This has been discussed on this list before, a search could turn up more
details.

Scott Jones

unread,
Apr 13, 2016, 9:30:17 AM4/13/16
to julia-users
There is no Float, you should use Float32 or Float64 depending on precision needed for your application.
I'd definitely use Int instead of Int64 as long as Int32 will be large enough, to avoid performance issues on 32-bit machines.
(I build and use Julia on my 32-bit ARM based Raspberry Pi)

Páll Haraldsson

unread,
Apr 16, 2016, 6:57:42 AM4/16/16
to julia-users
On Wednesday, April 13, 2016 at 9:27:00 AM UTC, Bill Hart wrote:
Int is either Int32 or Int64, depending on the machine. Int64 does still seem to be defined on a 32 bit machine. In fact, even Int128 is defined.

Yes, this is all safe when you only have one thread, but if you plan for the future (threads in Julia), I wander if only Int64 on 32-bit (and Int128, on 32- and 64-bit) is unsafe, as it is non-atomic:


See there "torn write". I saw a little surprised that all accesses in C/C++ can be non-safe.. so maybe that also applies to Julia.

Do I worry to much, as locks would be the way (or "lock-free"), to guard against non-atomic?

If you need big numbers keep BigNum in mind that I think should always be safe.

Christoph Ortner

unread,
Apr 17, 2016, 2:07:39 PM4/17/16
to julia-users
Why is there no `Float`? Is this discussed somewhere?

Kristoffer Carlsson

unread,
Apr 17, 2016, 2:09:01 PM4/17/16
to julia-users
Because of what Mauro said above.
Reply all
Reply to author
Forward
0 new messages