If (in my system) Int is an alias for Int32, then why there is no Float alias for Float32/64?

446 views
Skip to first unread message

Ismael VC

unread,
Feb 6, 2014, 4:47:07 PM2/6/14
to julia...@googlegroups.com
julia> type Patient
           age::Int
           height::Float
       end
ERROR: Float not defined

julia> type Patient
           age::Int
       end              

julia> Patient(7)
Patient(7)

julia> Float
Float64        Float32        Float16        FloatingPoint  
        
julia> Int
Int32               Int16               Integer             InterruptException  
Int                 Int64               Int8                Intrinsics          
Int128              IntrinsicFunction   IntSet              

julia> type Patient
           age::Int
           height::FloatingPoint
       end

julia> Patient(7, 1.20)
Patient(7,1.2)


Is FloatingPoint the same as using the Int alias for floats, so that if I run the script in a 64bit OS it can run unmodified?

Ismael VC

Patrick O'Leary

unread,
Feb 6, 2014, 4:58:15 PM2/6/14
to julia...@googlegroups.com
The standard floating point type in normal usage, even in 32-bit systems, is the 64-bit double precision type called "Float64" in Julia (and "double" in C). So using Float64 is typically the safest bet, and all other things equal will run equally well in both 32-bit and 64-bit environments, since floating point operations are handled in dedicated hardware.

Narrower floating-point types will typically show up in specific contexts: when only limited precision is required for an application and storage space is at a premium, when floating-point hardware is specialized for single precision operations (as in some SIMD and GPU applications), or when the architecture has no floating point hardware and is instead using software floating point (many microcontrollers and older ARM processors).

Ismael VC

unread,
Feb 6, 2014, 5:01:55 PM2/6/14
to julia...@googlegroups.com
Thank's Patrick! Very well explained.

Milan Bouchet-Valat

unread,
Feb 7, 2014, 3:18:10 AM2/7/14
to julia...@googlegroups.com
Le jeudi 06 février 2014 à 14:01 -0800, Ismael VC a écrit :
> Thank's Patrick! Very well explained.
Yeah, why not put this in the FAQ?
Message has been deleted

Felix

unread,
Feb 7, 2014, 7:26:24 AM2/7/14
to julia...@googlegroups.com


true; they should, but I guess to comply with the IEEE 754 standard 
so you can go for 64 or 32, they could have build in Float to 
detect the cpu arch type but there is a reason for not 
doing so.

Steven G. Johnson

unread,
Feb 7, 2014, 10:09:55 AM2/7/14
to julia...@googlegroups.com

Well, there is the fact that (a) this has nothing to do with Julia per se and (b) I'm not sure it is actually a frequent question.

Steven G. Johnson

unread,
Feb 7, 2014, 10:15:26 AM2/7/14
to julia...@googlegroups.com

There is no reason for doing so.  The size of addresses on your machine, or the widest hardware integer type, has nothing whatsoever to do with the width of floating-point types.   It also has nothing to do with the IEEE-754 standard (which specifies the format and behavior of 32- and 64-bit floating-point types, but not whether they are implemented in hardware or what they are called in computer languages).

This a common myth of 64-bit vs. 32-bit hardware.  I can't count the number of times I've heard the false statement that "32-bit machines had no 64-bit registers [false], so 64-bit machines will be faster at double-precision arithmetic [false]."  Almost as common as the old "64-bit machines process data twice as quickly as 32-bit machines" canard.

But again, this is just general information about computer architectures, nothing to do with Julia specifically.

Milan Bouchet-Valat

unread,
Feb 7, 2014, 10:46:37 AM2/7/14
to julia...@googlegroups.com
Let's say we'll reconsider this if a second persons asks the question on
a Julia list. ;-)

Ismael VC

unread,
Feb 7, 2014, 10:53:48 AM2/7/14
to julia...@googlegroups.com
I'd really love to see more examples in the manual, like Processing does:


For example Symbols! I've never encountered before, I'm not sure what they are and how to use them, or if Symbols are the same in every language that uses them?

I want to translate the documentation to spanish, but I still don't understand much of julia, and julia moves very fast, perhaps I'll wait until a stable release.


Felix

unread,
Feb 7, 2014, 11:00:57 AM2/7/14
to julia...@googlegroups.com
Ismeal VC
check the julia docs at http://docs.julialang.org/en/latest/
for the rest keep asking in this group someone will surely
help you out.

like look at a symbol as a safe string
when you do something like 

sym = :hello
you will always know sym is hello

you can also use it as an expression like


Steven G. Johnson

unread,
Feb 7, 2014, 11:35:47 AM2/7/14
to julia...@googlegroups.com


On Friday, February 7, 2014 10:53:48 AM UTC-5, Ismael VC wrote:
I'd really love to see more examples in the manual, like Processing does:


For example Symbols! I've never encountered before, I'm not sure what they are and how to use them, or if Symbols are the same in every language that uses them?

Symbols are analogous to symbols in Scheme or Lisp (which are preceded with ' rather than : as in Julia).  See e.g.

    http://docs.racket-lang.org/guide/symbols.html
    http://www.phyast.pitt.edu/~micheles/scheme/scheme7.html
    https://en.wikipedia.org/wiki/Symbol_%28programming%29

Steven G. Johnson

unread,
Feb 7, 2014, 11:39:55 AM2/7/14
to julia...@googlegroups.com
And here's another viewpoint, from Ruby (which also has :symbol syntax)

    http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol

Ismael VC

unread,
Feb 7, 2014, 11:46:34 AM2/7/14
to julia...@googlegroups.com
Thank's everyone, I like Julia's community a lot!  :)

Stefan Karpinski

unread,
Feb 7, 2014, 12:00:23 PM2/7/14
to Julia Users
Yes, the manual is a bit sparing with examples. We definitely are getting to the point where something more expansive with more examples is needed.

John Myles White

unread,
Feb 7, 2014, 12:02:44 PM2/7/14
to julia...@googlegroups.com
FYI, this claim about the safety of symbols is actually not true. You can reassign the bindings of sym just as easily as you can reassign the bindings of a variable bound to a.

-- John
Reply all
Reply to author
Forward
0 new messages