'Contract Violation; expected: real?; given #f

I'm sorry if this question has been answered before, but I've looked around and I can't really understand the explanation as to why I'm getting this error.

From what I understand I'm asking if a statement is true and then if it is I'm asking it to return an expression. And apparently I'm not allowed to get #t/#f answers and expressions? I'm not sure. Could someone help me understand.

This is my code.

(define (piecewise x)
  (define pi 3.142)
  (cond
    ((> x (* pi 2)) (- x (* 2 pi)))
    ((or ( > x (* pi -1) (= x ( * -1 pi)))) (sin x))
    ((or ( < x (* 2 pi)) (= x (* 2 pi))) (sin x))
    (else (- (- 1 x) pi))))


Solution 1:[1]

If I may, if we take all of the suggestions and use them to simplify the code a bit, we might get the following:

(define (piecewise x)
  (let* ((pi 3.142)
         (tau (* 2 pi)))
    (cond
     ((> x tau) 
      (- x tau))
     ((or (>= x (- pi))
          (<= x tau))
      (sin x))
     (else (+ x pi)))))

This runs without errors under both Racket and Guile. Whether it computes the function correctly, only the OP can say for certain.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1