Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

An idea to supervise a real?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
CADaSchtroumpf
329 Views, 5 Replies

An idea to supervise a real?

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)
))

 

5 REPLIES 5
Message 2 of 6
_Tharwat
in reply to: CADaSchtroumpf

Just an idea .

 

replace the getreal function with getdist function to accept any kind of real numbers .

Message 3 of 6
CADaSchtroumpf
in reply to: _Tharwat

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

Message 4 of 6

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

Message 5 of 6


@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

Kent Cooper, AIA
Message 6 of 6

Thank Kent,

 

Really I forgot to make condition (/= base real) to acquire the inclusive value

Now it is good, I understood

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost