Hi,
I want to supervise a real with the strictly upper integer value and the lower or equal value.
Here is what I have make but it don't work's when I give a negative integer in form of real
Sorry for rough traduction
((lambda ( / ) (setq q_pr (getreal "\n Real?: ")) (princ (strcat "\n" (rtos q_pr 2 3) " >= " (rtos (if (< q_pr 0.0) (- (float (1+ (abs (fix q_pr))))) (float (fix q_pr)) ) ) ) ) (princ (strcat "\n" (rtos q_pr 2 3) " < " (rtos (if (< q_pr 0.0) (- (float (abs (fix q_pr)))) (float (1+ (fix q_pr))) ) ) ) ) (prin1) ))
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Just an idea .
replace the getreal function with getdist function to accept any kind of real numbers .
For understand,
I want this:
5 > 4.3 >= 4
2 > 1.0 >= 1
1 > 0.5 >= 0
1 > 0.0 >= 0
0 > -0.75 >= -1
0 > -1.0 >= -1 (don't work with my code)
-1 > -1.25 >= -2
I have an answer on french forum
;Gilles Chanteau
(defun foo (d) ((lambda (n) (list (if (and (minusp d) (< d n)) (1- n) n ) (if (> n d) n (1+ n) ) ) ) (fix d) ) )
Thank
@CADaSchtroumpf wrote:I have an answer on french forum
....
Another way to return the same, first with prompting the User:
(setq
real (getreal "\nReal number: ")
base (fix real)
); setq
(if (and (< real 0) (/= base real)); [negative, not whole number]
(setq base (1- base))
); if
(list base (1+ base))
Or, as a function with an argument:
(defun bounds (real)
(setq base (fix real))
(if (and (< real 0) (/= base real))
(setq base (1- base))
); if
(list base (1+ base))
); defun
Thank Kent,
Really I forgot to make condition (/= base real) to acquire the inclusive value
Now it is good, I understood