Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.50 KB | None | 0 0
  1. (defun percentage-lineariser (x)
  2.   "Converts a percentage form into a more linear format. For example:
  3.  4/5 ->  80% -> -0.25
  4.  3/2 -> 150% ->  0.5
  5.  2/1 -> 200% ->  1.0
  6.  1/2 ->  50% -> -1.0
  7. This format is easier to work with difference-judging strategies such as
  8. EXPONENTIAL-MOVING-AVERAGE-STRATEGY. This function is undefined for negative
  9. and zero values."
  10.   (assert (plusp x) (x)
  11.           "Percentage must be positive")
  12.   (cond
  13.     ((> x 1) (1- x))
  14.     ((= x 1) 0)
  15.     ((< x 1) (- 1 (/ x)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement