Re: truncate/floor with logBase

Alastair Reid <[email protected]>
Newsgroups gmane.comp.lang.haskell.hugs.bugs
Message-ID <[email protected]>
Alastair:
>> Rounding error I suspect.

Thorsten Stocksmeier <[email protected]>
> Okay, but is that my fault or hugs'?

Rather than assign blame, I think I'll assign homework.  

  http://citeseer.nj.nec.com/goldberg91what.html

This computer surveys article which discusses issues of accuracy and
the like in floating point arithmetic.  I's well worth reading if you
haven't read it before.

Another detail worth being aware of is that Hugs uses single precision
arithmetic for both Float and Double.

> Independent of that: Is there a workaround? Before logBase I used
> log n / log 2 as a simulation of logBase 2. Still have to find out
> whether this solves the problem. (well maybe logBase *is* in fact
> log/log - must stick my nose into the prelude this afternoon)

If you want a log_2 function of type Int->Int, I'd write the obvious
recursive function.  (Or the less obvious one-liner using iterate,
takeWhile and length.)  If speed is very important, I'd probably crack
open some volume of Knuth's Art of Computer Programming which almost
certainly has a more cunniung algorithm.

--
Alastair Reid                 [email protected]  
Reid Consulting (UK) Limited  http://www.reid-consulting-uk.ltd.uk/alastair/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.