# Int and float functions

**URL:** <https://discourse.julialang.org/t/int-and-float-functions/106770>\
**Category:** General Usage\
**Tags:** float, int\
**Created:** [November 26, 2023, 10:26pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770 "2023-11-26T22:26:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Post date:** [November 26, 2023, 10:26pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/1 "2023-11-26T22:26:01Z")

</div>

Hello,  
Just a question: Why is the `Int` function capitalized and the `float` function lower-case?

```julia
julia> 0x0001 |> Int
1

julia> 0x0001 |> float
1.0

julia> 0x0001 |> Float
ERROR: UndefVarError: `Float` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[120]:1

julia> 0x0001 |> int
ERROR: UndefVarError: `int` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[121]:1

```

thanks !  
fdekerm

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [November 26, 2023, 10:36pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/2 "2023-11-26T22:36:31Z")

</div>

```julia
julia> 0x0001 |> Float64
1.0

```

---

<div class="post-metadata">

**Author:** ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Post date:** [November 26, 2023, 10:40pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/3 "2023-11-26T22:40:50Z")

</div>

Thanks for the answer, but it doesn’t really answer the question, which is more of a typographical nature.

`Int` and `float` both make the assumption of stockage on 64 bytes.

```julia
julia> typeof(0x0001 |> Int)
Int64

julia> typeof(0x0001 |> Int64)
Int64

julia> typeof(0x0001 |> float)
Float64

julia> typeof(0x0001 |> Float64)
Float64

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 26, 2023, 10:46pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/4 "2023-11-26T22:46:25Z")

</div>

> [@fdekerme](#):
>
> `Int` and `float` both make the assumption of stockage on 64 bytes.

Neither is correct. `Int` is an alias for a type, `Int32` on 32-bit systems, `Int64` on 64-bit systems. The method of `float` you invoke forwards to `AbstractFloat`, whose methods are mostly implemented to forward to `Float64`, but that’s not a guarantee for all possible methods e.g. `AbstractFloat(big(1))`. Moreover, the `float` function has other methods that don’t return an `AbstractFloat` type, e.g. `float(1:5)`. It’s not a type constructor.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 26, 2023, 10:52pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/5 "2023-11-26T22:52:38Z")

</div>

`Int` is a type name, and the name of the constructor of that type, not just a regular function, and all types are CapitalCase, by convention.

`float`, on the other hand, is not a type name, and not a constructor.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [November 26, 2023, 11:02pm UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/6 "2023-11-26T23:02:15Z")

</div>

`Int` is an alias for the system native integer type. That is usually `Int64` these days. For 32-bit systems, it will be `Int32`.

[https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/)

Importantly since this refers to a specific type, `Int(x)` will always return `Int`.

`float` is not a direct alias for a specific floating point type such as `Float64`. It can and does return distinct types depending on the input.

```julia
julia> Int(0x8) |> typeof
Int64

julia> float(8.f5) |> typeof
Float32

julia> float(8.5) |> typeof
Float64

julia> float(5 + 7im) |> typeof
ComplexF64 (alias for Complex{Float64})

```

`Int` and `float` are thus not analogous functions. Often if you wanted to convert a non-integer type to an integer you would need to do something such as `round(Int, x)`.

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [November 27, 2023, 5:39am UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/7 "2023-11-27T05:39:35Z")

</div>

I am more curious to know why there is no `int` while there is a `float`.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 27, 2023, 6:43am UTC](https://discourse.julialang.org/t/int-and-float-functions/106770/8 "2023-11-27T06:43:55Z")

</div>

int-ifying runs into rounding or magnitude issues far more easily, and there’s no convenient default way to handle those, so might as well manually do it with a bunch of other functions and arguments.
