[plt-scheme] order of magnitude

From: Jos Koot (jos.koot at telefonica.net)
Date: Thu Nov 5 07:27:04 EST 2009

Your example assumes that (/ (log n) (log 10)) always is too small, which cannot be trusted to be always true, I think.
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 1:12 PM
Subject: Re: [plt-scheme] order of magnitude


2009/11/5 Jos Koot <jos.koot at telefonica.net>:
> Some browsing did not lead me to finding a function that accepts an exact
> positive rational number and returns its order of magnitude (an exact
> integer number) Something like:
>
snip

> However, this seems rather complicated. Does someone have or know of a
> simpler and faster function for this purpose?

I might be missing something, but what about this?

(define (order n)
  (inexact->exact (floor (+ 1 (/ (log n) (log 10))))))

Note: It returns the same numbers as used in:
  http://en.wikipedia.org/wiki/Order_of_magnitude
so it gives slightly different results than your
function.

-- 
Jens Axel Søgaard




Posted on the users mailing list.