For what it's worth, here is my Scheme function for converting from RGB to HSV. All inputs and outputs should be normalized to fall within the range 0.0 to 1.0 .
; (rgb->hsv r g b) ==> (h s v)
; inputs and outputs all normalized from 0.0 to 1.0
;
(define rgb->hsv
(lambda rgb
(let* ((v (apply max rgb))
(d (- v (apply min rgb)))
(s (if (zero? v)
0.0
(/ d v)))
(h (cond
((zero? v)
0.0)
((< d 0.00001)
v)
((= (car rgb) v)
(/ (- (cadr rgb) (caddr rgb)) 6 d))
((= (cadr rgb) v)
(+ (/ 3) (/ (- (caddr rgb) (car rgb)) 6 d)))
((= (caddr rgb) v)
(+ (/ 2 3) (/ (- (car rgb) (cadr rgb)) 6 d))))))
(list (if (< h 0)
(+ h 1)
h)
s
v))))