Exact and inexact numbers

The problem is that if you give max (or any other arithmetic function) mixed exact and inexact arguments, it will return an inexact answer:

  (max 3 5 8)
  ;Value: 8

  (max 3 5.0 8)
  ;Value: 8.

This sort of problem is not unique to scheme. Just this past week I had a related problem in C with signed chars being converted to ints for arithmetic/logic operations, and i had to do some unexpected typecasting to make it work right. I'll argue that scheme does a better job than most languages of shielding users from such silliness.

Anyway, the problem is that 8 (exact) and 8. (inexact) have the following property:

(equal? 8 8.)
;Value: ()

(= 8 8.)
;Value: #t

The member function uses equal? to compare the given element to elements in the list. As for a solution, how about:

(define d '(3 5.0 8))
;Value: d

(member (apply max d) (reverse d))
;Value: ()

(let ((d-inexact (map exact->inexact d)))
  (member (apply max d-inexact) (reverse d-inexact)))
;Value 2: (8. 5. 3.)

--wh