guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multi-language cookbook effort


From: Kalle Olavi Niemitalo
Subject: Re: Multi-language cookbook effort
Date: 20 Aug 2001 10:44:32 +0300

Alex Shinn <address@hidden> writes:

> ;; @@PLEAC@@_2.2
> 
> ;; (approx-equal? num1 num2 accuracy) : returns #t if num1 and num2 are
> ;;   equal to accuracy number of decimal places
> (define (approx-equal? num1 num2 accuracy)
>   (< (- num1 num2) (expt 10.0 (- accuracy))))

guile> (approx-equal? 1 9999999 10)
#t

I think you need "abs".

> ;; @@PLEAC@@_2.3
> 
> (round num)                           ;; rounds to inexact whole number
> (inexact->exact num)                  ;; rounds to exact integer

It would be nice to warn that R5RS doesn't require inexact->exact
to round to an integer.

> ;; @@PLEAC@@_2.8
> 
> ;; if you're working with random numbers you'll probably want to set
> ;; the random seed
> 
> (seed->random-state (current-time))

Perhaps assign it to *random-state* too.

> ;; @@PLEAC@@_2.11
> 
> ;; Guile's trigonometric functions use radians.
> 
> (define pi 3.14159265358979)
> 
> (define (degrees->radians deg)
>   (* PI (/ deg 180.0)))
> 
> (define (radians->degrees rad)
>   (* 180.0 (/ rad PI)))

This needs (read-enable 'case-insensitive).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]