division in lisp

division in lisp

GeryKnee
Advocate Advocate
812 Views
5 Replies
Message 1 of 6

division in lisp

GeryKnee
Advocate
Advocate

There is an error here :


(defun c:xxx(/)
(setq Scale (getInt "\scale : "))
(setvar "celtscale" (/ Scale 1000) )
(princ)
)

 

error: AutoCAD variable setting rejected: "celtscale" 0

 

Thanks,

Gery.

 

 

0 Likes
Accepted solutions (2)
813 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

(setvar "celtscale" (/ Scale 1000.0))

zero because integer divided by an integer is an integer.

You need to hah at least one real to make a result a real number. So use 1000.0 or simply 1000. (with dot at the end)

Message 3 of 6

GeryKnee
Advocate
Advocate

OK

Thank you very much Sir,

Regards,

Gery.

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor
Accepted solution

You have to be careful about Real and integers, when in doubt as suggested use a "."

 

(/ 1 3)
0

(/ 1 3.)
0.3333333

(/ 3 2)
1
(/ 3. 2.)
1.5

(* 2 pi)

(* pi 2)
6.28318530717959 note as PI is a real 

 

 

Message 5 of 6

GeryKnee
Advocate
Advocate

Thank you Sea.heaven,

I think that
(/ 3. 2.) and 
(/ 3. 2)

have the same result = 1.5

regards,

Gery

0 Likes
Message 6 of 6

hak_vz
Advisor
Advisor

You have

(defun c:xxx(/)
(setq Scale (getInt "\scale : "))
(setvar "celtscale" (/ Scale 1000) )
(princ)
)

Instead of getint use getreal

(defun c:xxx(/)
(setvar "celtscale" (/ (getreal "\nScale : ") 1000) )
(princ)
)

In most situation we work with real numbers.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes