flonum-arith.scm 929 B

12345678910111213141516171819202122232425262728293031323334
  1. (define (binary-flonum-op proc)
  2. (lambda (x y)
  3. (save-temp0! x)
  4. (save-temp1! y)
  5. (let ((key (ensure-space double-size)))
  6. (enter-double (proc (extract-double (recover-temp0!))
  7. (extract-double (recover-temp1!)))
  8. key))))
  9. (define flonum-add (binary-flonum-op fl+))
  10. (define flonum-subtract (binary-flonum-op fl-))
  11. (define flonum-multiply (binary-flonum-op fl*))
  12. (define (flonum-divide x y)
  13. (if (fl= (extract-double y)
  14. 0.0)
  15. false
  16. ((binary-flonum-op fl/) x y)))
  17. (define (flonum-comparison proc)
  18. (lambda (x y)
  19. (proc (extract-double x)
  20. (extract-double y))))
  21. (define flonum= (flonum-comparison fl=))
  22. (define flonum< (flonum-comparison fl<))
  23. (define flonum> (flonum-comparison (lambda (x y)
  24. (fl< y x))))
  25. (define flonum<= (flonum-comparison (lambda (x y)
  26. (not (fl< y x)))))
  27. (define flonum>= (flonum-comparison (lambda (x y)
  28. (not (fl< x y)))))