[erlang-questions] Floor Function?

Hynek Vychodil vychodil.hynek@REDACTED
Tue Mar 17 10:23:37 CET 2009


You are right, computing X-T if you want know if X<T is wrong approach. I
was react before think.

On Tue, Mar 17, 2009 at 12:15 AM, Richard O'Keefe <ok@REDACTED> wrote:

> I wrote:
>
>> There doesn't seem to be any reason to compute X-T.
>>
>>  On 17 Mar 2009, at 12:44 am, Hynek Vychodil wrote:
>
>> 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 ...
>>
>>  This misses the point.
> The existing version requires 40 tokens,
> the simplified version requires 26.
> Never mind the computer, it's a heck of a lot easier for PEOPLE
> to think and to read.  Again, the existing version does one
> subtraction and three comparisons, while the simplified version
> does one comparison.  Never mind the computer, it's a heck of a
> lot easier for PEOPLE to think and to read.
>
> In general, there is a *correctness* issue in using
> X - Y when you really mean X <relop> Y.  Just last week
> I had occasion to point out to someone that using
>        static int intcmp(void const *x, void const *y) {
>            return *(int const *)x - *(int const *)y;
>        }
> as a comparison function in C's qsort() is *guaranteed* to
> give wrong answers.  Thanks to bignums -- I don't know who
> decided that Erlang would have bignums but it was a really
> excellent decision -- Erlang doesn't have that particular
> problem, but there is a similar problem involving floats.
> That doesn't apply in this case either, but it _is_ enough
> of a problem that we do NOT want people to get into the
> habit of "comparing" numbers by subtracting them.  It's FAR
> too error-prone.
>
> There are other reasons (simplicity, error-proneness) to
> prefer one approach to another than just machine efficiency.
>
>


-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090317/8506b8b4/attachment.htm>


More information about the erlang-questions mailing list