Why does "Int" exist, but not "Float"?

Viewed 60

I saw that when using parse for example, you can do this: parse(Int, "123") (Int exists), but I can't do parse(Float, "12.3") (Float doesn't exist).

Why doesn't Float exist as well then? What is the difference between Int and for example Int64 or some other number after Int anyways (I know it has to do with the size, but how can you know when to use which)?

1 Answers

The reason for this is that machines are either 32 bit or 64 bit. This is the size of pointers on these machines, and since pointers are just integers in hardware, it is also the "natural" integer size. Floating point arithmetic is different. (Almost) all computers have both FLoat32 and Float64, and the choice needs to be made based on application (how much range and accuracy you need). That said, you could always define const Float = Float64 and then just use Float.

Related