How do you do Log N, Log 2, Log 10 in Gambit?
4 Aug
2018
4 Aug
'18
5:14 a.m.
Hi, How do you do Log N, Log 2 and Log 10 in Gambit? Thanks! Adam
4 Aug
4 Aug
7:35 a.m.
On Aug 4, 2018, at 11:14 AM, Adam <adam.mlmb@gmail.com> wrote:
Hi,
How do you do Log N, Log 2 and Log 10 in Gambit?
Thanks! Adam
(- (integer-length 1024) 1) 10
(/ (log 1000) (log 10)) 2.9999999999999996 (/ (log 1024) (log 2))
(exp 1) 2.718281828459045 (log (exp 1))
The procedure integer-length can be useful for exact integers if you want an exact integer result. Marc
8:08 a.m.
2018-08-04 19:35 GMT+08:00 Marc Feeley <feeley@iro.umontreal.ca>: > > > On Aug 4, 2018, at 11:14 AM, Adam <adam.mlmb@gmail.com> wrote: > > > > Hi, > > > > How do you do Log N, Log 2 and Log 10 in Gambit? > > > > Thanks! > > Adam > > > (exp 1) > 2.718281828459045 > > (log (exp 1)) > 1. > > (/ (log 1000) (log 10)) > 2.9999999999999996 > > (/ (log 1024) (log 2)) > 10. > While this may understandably appear trivial for you, would you mind to give one minute to spell out the code for (define (log2 n) ...) (define (log10 n) ...) (define (logn n base) ...) ? > > (- (integer-length 1024) 1) > 10 > > The procedure integer-length can be useful for exact integers if you want > an exact integer result. > Ah interesting, |integer-length| counts an exact integer's significant bits > (integer-length 1) 1 > (integer-length 2) 2 > (integer-length 4) 3 > (integer-length 8) 4 > (integer-length 16) 5 Right, so this gives us something like, for |n| > 0, (define (integer-log2 n) (- (integer-length n) 1))
8:27 a.m.
On Aug 4, 2018, at 2:08 PM, Adam <adam.mlmb@gmail.com> wrote:
While this may understandably appear trivial for you, would you mind to give one minute to spell out the code for
(define (log2 n) (logn n 2)) (define (log10 n) (logn n 10)) (define (logn n base) (/ (log n) (log base))) Marc
2902
Age (days ago)
2902
Last active (days ago)
3 comments
2 participants
participants (2)
-
Adam -
Marc Feeley