# Why no Float type alias?

**URL:** <https://discourse.julialang.org/t/why-no-float-type-alias/87947>\
**Category:** General Usage\
**Tags:** question, type\
**Created:** [September 28, 2022, 7:20pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947 "2022-09-28T19:20:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [September 28, 2022, 7:20pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/1 "2022-09-28T19:20:23Z")

</div>

Why doesn’t `Float` alias to the machine bit size like `Int`?

```julia
julia> Int
Int64

julia> Float
ERROR: UndefVarError: Float not defined

```

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [September 28, 2022, 7:27pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/2 "2022-09-28T19:27:39Z")

</div>

There’s no need for it.

Float64 is always a 64-bit type and Float32 is always 32-bit etc. and Int64 is always 64-bit and all types are on all platforms, but Int is usually 64-bit (not strictly an alias, so don’t really on it being more than Int32), i.e. except for on 32-bit platforms, where it’s always 32-bit. If you need 64-bit or larger integers, always use Int64, Int128 (or their unsigned types) or BigInt.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [September 28, 2022, 7:36pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/3 "2022-09-28T19:36:07Z")

</div>

I would think `Float == Float32` on 32 bit systems and `Float == Float64` on 64 bit systems, so the precision depends on the system. Why is this behavior needed for `Int`s but not `Float`s?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [September 28, 2022, 7:40pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/4 "2022-09-28T19:40:02Z")

</div>

32 bit systems usually still have Float64 hardware. The 32 bitness is related to the address space, and is independent of the parts of the chip used for doing floating point math.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [September 28, 2022, 7:40pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/5 "2022-09-28T19:40:03Z")

</div>

No, it’s never been that way, Float64, aka double in C and C++ existed on 32-bit systems, even 16-bit.\*

For array indices you want to use `Int`, i.e. the machine integer you have. If it were Int64, then twice as large on 32-bit and that’s not needed or wanted.

If you want e.g. to support money, then `Int` is the wrong type.

`*` Actually the history is more complex, double may have been 80-bit, even on those systems, but 80-bit is outdated and slower on current platforms, and not supported on all platforms Julia supports. I will not explain pre-IEEE hexadecimal floating point (still used in FDA standard files) and and 36/72-bit binary floating point of ancient systems.

36-bit floats in some form might make a comeback in some form, though I bet against it: [Simplest of All](http://www.quadibloc.com/arch/per05.htm)  
[https://groups.google.com/g/comp.arch/c/h4yjn8BP54g](https://groups.google.com/g/comp.arch/c/h4yjn8BP54g)

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [September 28, 2022, 7:54pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/6 "2022-09-28T19:54:51Z")

</div>

My understanding is that you can use any precision on any system by grouping bytes. The question is why there is an easy option to use a machine’s native precision for `Int` but not that option for `Float`. The difference between `Int` and `Float` is just how that string of 32 or 64 bits is interpreted right?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 28, 2022, 7:56pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/7 "2022-09-28T19:56:34Z")

</div>

32 bit systems have 64 bit FP registers

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [September 28, 2022, 7:58pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/8 "2022-09-28T19:58:31Z")

</div>

> [@\`Float\` type like \`Int\` type](https://discourse.julialang.org/t/float-type-like-int-type/1164):
>
> I find myself always writing a type alias for floating points in order to make my package neutral to machine word size: typealias Float Float64 Why there is no definition like Int that becomes Int64 or Int32 depending on the host machine? Could you please explain the rationale for this?

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [September 28, 2022, 8:01pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/9 "2022-09-28T20:01:18Z")

</div>

I swear I tried to search before posting …

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [September 28, 2022, 8:44pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/10 "2022-09-28T20:44:52Z")

</div>

> [@Nathan\_Boyer](#):
>
> My understanding is that you can use any precision on any system by grouping bytes. The question is why there is an easy option to use a machine’s native precision for `Int` but not that option for `Float`. The difference between `Int` and `Float` is just how that string of 32 or 64 bits is interpreted right?

In terms of storage, yes. But CPUs for at least the past couple decades have all had specialize hardware made specifically for accellerating math on various floating point datatypes, and these are specialized to the size of the data. This specialized hardware has existed for Float64 for a very long time.

This hardware is also why Julia can’t just decide how floating point math works (if we want that math to be fast). We are ultimately at the mercy of existing hardware decisions when it comes to things like the behaviour of `0.1 + 0.2 != 0.3`

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [September 28, 2022, 9:56pm UTC](https://discourse.julialang.org/t/why-no-float-type-alias/87947/11 "2022-09-28T21:56:31Z")

</div>

It was a valid question, and to not necropost on the other, which I didn’t recall, I do support Julia explicit (about size) and I might make a type P16, because I think Posit16 might be a happy medium of sizes (see SoftPostit.jl), but not as an alias of Posit16, but with my own extension of it (base 30), stay tuned…

Some background (right now I’m focused on smaller floats for neural networks, but general purpose might needs Posit16, with or without my twist):

> [@RFC: Compressed (base-6) floating point, taking 1/8 the space (new plan 1/64 compression for neural networks)](https://discourse.julialang.org/t/rfc-compressed-base-6-floating-point-taking-1-8-the-space-new-plan-1-64-compression-for-neural-networks/87289):
>
> I’ll likely be making a package later, but this may already be useful for someone. I though about posting under performance category, but so far decided against, since I’m not (yet) asking for tuning advice, but this would of course help others, with performance; memory-bandwidth. I’ll first show the (potential) downsides. Likely fixed by B. when bug found. A. julia\> decode\_8(encode\_8((-0.0, 12.0, 3.0, 4.0, 12.0, 3.0, 5.0, 1/3))) (0.0, 12.0, 3.0, 4.0, 12.0, 3.0, 5.0, 0.3333333333333333) You …
