On 9 October 2014 09:58, Hubert Soyer <
hubert...@gmail.com> wrote:
>
> Is there any way to make floats in Julia default to 32 bit on a 64 bit
> system?
> At least in a lot of my work 32 bit precision is just fine and the speed I
> could potentially gain by simply switching is enormous.
I think Patrick already handled the 32-bit vs 64-bit version confusion
nicely, so I will take a stab at the rest of the question. Avoiding
64-bit floats is not uncommon, 32-bit is the standard for most games
and I have even heard of 16-bit floats being used for real time
imaging systems.
However, as far as I know, there is no way to switch the whole inner
workings of Julia to default to 32-bit floats, I am far from a
seasoned Julia programmer though, so I may be wrong. The best way I
can come up with is to use some type aliasing.
typealias Float Float32
Then, wherever you may need to assign a float you would simply
constrain the variable as being `Float`.
x::Float = 1.0
This should make switching between 64/32/16-bit floats easy and keep
your code reasonably clean. Just keep in mind that you can not do
this at the top level of a module, I can not remember the current
technical reason though, but would need something along the lines of
`x = convert(Float, 1.0)`.
Pontus