[erlang-questions] Floor Function?

Hynek Vychodil vychodil.hynek@REDACTED
Mon Mar 16 12:44:25 CET 2009

```On Mon, Mar 16, 2009 at 5:10 AM, Richard O'Keefe <ok@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.
>

Are you sure that there is big difference between compute X-T and decide X<T
or which one is less expensive? I'm not! If you haven't measured ...

>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>

--
--Hynek (Pichi) Vychodil