Proposal: Float.to_integer

42 views
Skip to first unread message

Kelvin Raffael Stinghen

unread,
Jan 3, 2018, 6:57:41 AM1/3/18
to elixir-lang-core
The argument to include it is discovery. I use to search the Reference module given by `IEx.Helpers.i/1` when I need a function related to some data, and I had hard times trying to a function to convert a `Float` to an `Integer`.

I know `Kernel.round/1` rounds to the nearest integer, but the `Kernel` module didn't even come to my mind, I found this in a blog post.

José Valim

unread,
Jan 3, 2018, 7:04:55 AM1/3/18
to elixir-l...@googlegroups.com
Let's start by improving the docs in the Float module.

We can start with a short explanation on floating point arithmetic and in another section include a list of functions that work with floats in Kernel, such as round/1 and trunc/1. It is worth noting those functions are also guard allowed



José Valim
Founder and 
Director of R&D

On Wed, Jan 3, 2018 at 12:57 PM, Kelvin Raffael Stinghen <kelvin....@gmail.com> wrote:
The argument to include it is discovery. I use to search the Reference module given by `IEx.Helpers.i/1` when I need a function related to some data, and I had hard times trying to a function to convert a `Float` to an `Integer`.

I know `Kernel.round/1` rounds to the nearest integer, but the `Kernel` module didn't even come to my mind, I found this in a blog post.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/00c5e472-a5cc-4000-8a0a-a55f4fcc1316%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kelvin Raffael Stinghen

unread,
Jan 3, 2018, 7:28:20 AM1/3/18
to elixir-l...@googlegroups.com
> Let's start by improving the docs in the Float module.

That should work very well indeed. But I still feel a `to_integer` function would be easier to find.

> We can start with a short explanation on floating point arithmetic and in another section include a list of functions that work with floats in Kernel, such as round/1 and trunc/1

I'll open a PR for it. ;)

> It is worth noting those functions are also guard allowed

Yep, I’ve noticed that. Is this the argument to have them as Kernel functions? Why not having a `Float.to_integer(float, :round | :trunc)` inlined by the compiler and guard allowed too?

Best,
Kelvin Stinghen

José Valim

unread,
Jan 3, 2018, 7:34:31 AM1/3/18
to elixir-l...@googlegroups.com
Yep, I’ve noticed that. Is this the argument to have them as Kernel functions? Why not having a `Float.to_integer(float, :round | :trunc)` inlined by the compiler and guard allowed too?

Yeah, since they work on guards, they are in Kernel. And we decided (quite some time ago) to not duplicate the Kernel functions in specific modules.



José Valim
Founder and 
Director of R&D

On Wed, Jan 3, 2018 at 1:28 PM, Kelvin Raffael Stinghen <kelvin....@gmail.com> wrote:
> Let's start by improving the docs in the Float module.

That should work very well indeed. But I still feel a `to_integer` function would be easier to find.

> We can start with a short explanation on floating point arithmetic and in another section include a list of functions that work with floats in Kernel, such as round/1 and trunc/1

I'll open a PR for it. ;)

> It is worth noting those functions are also guard allowed

Yep, I’ve noticed that. Is this the argument to have them as Kernel functions? Why not having a `Float.to_integer(float, :round | :trunc)` inlined by the compiler and guard allowed too?

Best,
Kelvin Stinghen

On Jan 3, 2018, at 10:04, José Valim <jose....@gmail.com> wrote:

Let's start by improving the docs in the Float module.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

Kelvin Raffael Stinghen

unread,
Jan 19, 2018, 7:27:21 AM1/19/18
to elixir-lang-core
Just to mention the Float docs improvement suggested is on master ❤️ 💚 💙 💛 💜


On Wednesday, January 3, 2018 at 10:34:31 AM UTC-2, José Valim wrote:
Yep, I’ve noticed that. Is this the argument to have them as Kernel functions? Why not having a `Float.to_integer(float, :round | :trunc)` inlined by the compiler and guard allowed too?

Yeah, since they work on guards, they are in Kernel. And we decided (quite some time ago) to not duplicate the Kernel functions in specific modules.



José Valim
Founder and 
Director of R&D

On Wed, Jan 3, 2018 at 1:28 PM, Kelvin Raffael Stinghen <kelvin....@gmail.com> wrote:
> Let's start by improving the docs in the Float module.

That should work very well indeed. But I still feel a `to_integer` function would be easier to find.

> We can start with a short explanation on floating point arithmetic and in another section include a list of functions that work with floats in Kernel, such as round/1 and trunc/1

I'll open a PR for it. ;)

> It is worth noting those functions are also guard allowed

Yep, I’ve noticed that. Is this the argument to have them as Kernel functions? Why not having a `Float.to_integer(float, :round | :trunc)` inlined by the compiler and guard allowed too?

Best,
Kelvin Stinghen

On Jan 3, 2018, at 10:04, José Valim <jose....@gmail.com> wrote:

Let's start by improving the docs in the Float module.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages