<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 04/06/2016 06:33, Dan Gudmundsson
wrote:<br>
</div>
<blockquote
cite="mid:CANX4uuO8rSZs0qm3P1m+2WS8WhOGgRYb0YeDDRhjtXqDrJEc6Q@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_quote">
<div dir="ltr">On Fri, Jun 3, 2016 at 11:38 PM Samuel <<a
moz-do-not-send="true" href="mailto:samuelrivas@gmail.com"><a class="moz-txt-link-abbreviated" href="mailto:samuelrivas@gmail.com">samuelrivas@gmail.com</a></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 moz-do-not-send="true"
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>
<br>
</div>
</div>
</blockquote>
<br>
Is there any reason why there may not be two functions, one
returning float and one returning integer? One function won't cover
all scenarios and trying to discuss which one is better in that
context will never end. If only one type of function is possible
then it would be best to verify which usage is more common out there
- in real applications - so that the decision isn't speculative but
backed by some data.<br>
<br>
Grzegorz<br>
</body>
</html>