[erlang-questions] Floor Function?

Steve Davis steven.charles.davis@REDACTED
Mon Mar 16 12:51:15 CET 2009


Why isn't that...

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.

;-P

On Mar 15, 11:10 pm, "Richard O'Keefe" <o...@REDACTED> wrote:
> 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.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list