# [plt-scheme] order of magnitude

 From: Jos Koot (jos.koot at telefonica.net) Date: Thu Nov 5 09:29:10 EST 2009 Previous message: [plt-scheme] order of magnitude Next message: [plt-scheme] order of magnitude Messages sorted by: [date] [thread] [subject] [author]

```Mathematically your derivation is correct, but computationally it may be incorrect. The problem is that in an actual computation, e.g. in Scheme,

(expt 10 (/ (log q) (log 10)))

may be
slightly  less than q
or exactly equal to q
or slightly greater than q.

This holds even when q is exact, for log is not required to and often even cannot produce an exact result. In fact I do not even trust that the absolute error of (/ (log q) (log 10)) is allways less than one, where absolute error is the difference between mathematical value and actually computed value. As another axample:

(- 2 (sqr (sqrt 2))) ; --> -4.440892098500626e-016 and hence:
(zero? (- 2 (sqr (sqrt 2)))) --> #f
Jos

----- Original Message -----
From: "Jens Axel Søgaard" <jensaxel at soegaard.net>
To: "Jos Koot" <jos.koot at telefonica.net>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Thursday, November 05, 2009 2:58 PM
Subject: Re: [plt-scheme] order of magnitude

2009/11/5 Jos Koot <jos.koot at telefonica.net>:
> Let q be a positive rational (or real) number.
> I am looking for the greatest integer number m such that:
> (<= (expt 10 m) q)

I get:

greatest integer m s.t.:   10^m <= q
greatest integer m s.t.:   log(10^m) <= log(q)
greatest integer m s.t.:   m*log(10) <= log(q)
greatest integer m s.t.:   m <= log(q)/log(10)
m = floor(log(q)/log(10))

--
Jens Axel Søgaard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091105/e0612ef9/attachment.html>
```

 Posted on the users mailing list. Previous message: [plt-scheme] order of magnitude Next message: [plt-scheme] order of magnitude Messages sorted by: [date] [thread] [subject] [author]