The "...+" means "takes at least one argument".

> (+)
0
> (max)
max: expects at least 1 argument, given 0
>

I think the preferred way to check for inexact equality is to compare the absolute difference with a small tolerance, like you were looking for.

(require rackunit)

(define (inexact=? a b epsilon)
  ((abs (- a b)) . < . epsilon))

(check-false (inexact=? 1 2 0.1))
(check-true (inexact=? 1 1.05 0.1))


There are more sophisticated ways to do this, but they're harder to understand and I've never seen them implemented in a math library.

Neil T

On 10/03/2011 10:55 AM, John Riedl wrote:
In section 3.2.2 of the online Racket documentation a number of the
signatures of the functions end with "+", e.g.,:

(max x ...+) → real?

Most signatures do not have the +, including those that take an
arbitrary number of arguments, e.g.,:

(+ z ...) → number?

Do the plus signs mean anything, or are they just typos?

(The reason I was looking is to see if there is a version of equal?
that takes a tolerance, like check-=? from rackunit.  What is the
preferred way to check equality for inexact numbers?)

Thanks!
John

_________________________________________________
   For list-related administrative tasks:
   http://lists.racket-lang.org/listinfo/users

_________________________________________________
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users

Reply via email to