Originally Posted by
rkmcswain
what about this?
Code:
(distof (rtos 1.903234 5 4) 2)
;;;
;;;
: (distof (rtos 1.2689 5 4) 2)
1.25
: (distof (rtos 1.8845 5 4) 2)
1.875
: (distof (rtos 0.998 5 4) 2)
1.0
: (distof (rtos 0.4389 5 4) 2)
0.4375
Thank you. I have to read up on 'distof' and 'rtos' to understand what you posted. I came up with something below using Lee Mac subroutines
Code:
;; Round Down - Lee Mac
;; Rounds 'n' down to the nearest 'm'
(defun LM:rounddown ( n m )
((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r m)) ((- n r)))) (rem n m))
)
;; Round Up - Lee Mac
;; Rounds 'n' up to the nearest 'm'
(defun LM:roundup ( n m )
((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r)) ((+ n (- m r))))) (rem n m))
)
(defun AS:round16th (x)
(setq d1 (- (LM:roundup x 0.0625) x))
(setq d2 (- x (LM:rounddown x 0.0625)))
(cond ((> d1 d2) (LM:rounddown x 0.0625))
(T (LM:roundup x 0.0625))
)
)
(setq y (AS:round16th 0.468))
Edit:
After playing around with your code it works great (and a hell of a lot simpler!!)
Thanks