<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, Jun 3, 2016 at 11:38 PM Samuel <<a href="mailto:samuelrivas@gmail.com">samuelrivas@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>> I made pull request <a href="https://github.com/erlang/otp/pull/1084which" rel="noreferrer" target="_blank">https://github.com/erlang/otp/pull/1084which</a><br>
>> implements ceil and floor in the math module.<br>
>><br>
>> The question is, should they return integer or floats?<br>
><br>
><br>
> Yes, they should.  For each of floor, ceiling, round, truncate there are<br>
> two sensible functions: one returns the appropriate integer as an integer,<br>
> and the other returns it as a floating-point number.<br>
<br>
What is the use case when you want floor/ceil to return a float and<br>
not an integer in Erlang?<br>
<br>
Since Erlang has bignums, which I understand can represent the integer<br>
part of any float,  and those operations are supposed to return an<br>
integer I can't see a reason for a float result (other than, maybe,<br>
performance).<br>
<br></blockquote><div><br></div><div>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.</div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5"> </span><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Best<br>
--<br>
Samuel<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div></div>