[erlang-questions] Floor Function?
Richard O'Keefe
ok@REDACTED
Mon Mar 16 05:10:39 CET 2009
On 14 Mar 2009, at 7:17 am, Bob Ippolito wrote:
> int_ceil(X) ->
> T = trunc(X),
> case (X - T) of
> Neg when Neg < 0 -> T;
> Pos when Pos > 0 -> T + 1;
> _ -> T
> end.
Why isn't this
int_ceil(X) ->
T = trunc(X),
if X > T -> T + 1
; true -> T
end.
int_floor(X) ->
T = trunc(X),
if X < T -> T - 1
; true -> T
end.
There doesn't seem to be any reason to compute X-T.
More information about the erlang-questions
mailing list