[erlang-questions] math ceil floor

Dan Gudmundsson dangud@REDACTED
Sat Jun 4 08:33:28 CEST 2016

On Fri, Jun 3, 2016 at 11:38 PM Samuel <samuelrivas@REDACTED> wrote:

> >> I made pull request https://github.com/erlang/otp/pull/1084which
> >> implements ceil and floor in the math module.
> >>
> >> The question is, should they return integer or floats?
> >
> >
> > Yes, they should.  For each of floor, ceiling, round, truncate there are
> > two sensible functions: one returns the appropriate integer as an
> integer,
> > and the other returns it as a floating-point number.
> What is the use case when you want floor/ceil to return a float and
> not an integer in Erlang?
> Since Erlang has bignums, which I understand can represent the integer
> part of any float,  and those operations are supposed to return an
> integer I can't see a reason for a float result (other than, maybe,
> performance).
My reason for a variant that returns a float is purely performance the beam
compiler is good at avoiding conversion/type checking floats in code blocks
that handle floats, and sometimes you want to continue to work with the
result as float, e.g. multiply the result with another float.

> Best
> --
> Samuel
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160604/6c361ab8/attachment.htm>

More information about the erlang-questions mailing list