Author Topic: (/ 1 100) = ??  (Read 3855 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
(/ 1 100) = ??
« on: October 28, 2005, 03:55:29 PM »
Hi all..

I have many old lisp routine that i haven't created...
but who is now my job to arrange....

many of these use calculation ethod..
but somme error comes..

I have this simple calculation..  (/ 1 100)
supposed to have result 0.01.

But AutoCAd give me   0  !!??

My LUPREC is 8
and my LUNITS is 2

any idea ??

Keep smile...

TR

  • Guest
Re: (/ 1 100) = ??
« Reply #1 on: October 28, 2005, 03:59:52 PM »
Command: (/ 1.00 100.00)
0.01

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (/ 1 100) = ??
« Reply #2 on: October 28, 2005, 04:03:53 PM »
heun !?? :?

Why now we need to put a point ??
when the first number is minus than the second ??

Commande: (/ 1. 100)
0.01

Commande: (/ 2 100)
0

Commande: (/ 200 100)
2

Commande: (/ 20 100)
0

Commande: (/ 20 10)
2


!!????   :|  strange..
Keep smile...

LE

  • Guest
Re: (/ 1 100) = ??
« Reply #3 on: October 28, 2005, 04:14:22 PM »
If you want to have a REAL value returned, then you can do any of the following statements:

Code: [Select]
(/ 1.0 4) => 0.25

Code: [Select]
(/ 1 4.0) => 0.25

Code: [Select]
(/ 1.0 4.0) => 0.25

HTH

TR

  • Guest
Re: (/ 1 100) = ??
« Reply #4 on: October 28, 2005, 04:19:33 PM »
Sorry brother, I'm not a lisper. I assume that since 1 and 100 are integers instead of floating point integers it will naturally return an integer. By typing 1.00 and 100.00 you are defining them as a floating point integer and thus it will return one.

That is a guess of course. However this is common in dynamically typed languages.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (/ 1 100) = ??
« Reply #5 on: October 28, 2005, 04:28:39 PM »
Not strange at all.

Because you have declared the values as integers the Autolisp interpreter/compiler conforms, and rounds the operation result values accordingly.

VB/A does the same thing with literal values.

This is a cause of countless errors/anomolies.

.. another is applying arithmatic operators to integers where the result is larger than the integer legal capacity.

eg
(+ 2147483640  10)
;=> -2147483646


.... That is a guess of course. However this is common in dynamically typed languages.
Yes.
« Last Edit: October 28, 2005, 04:33:16 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: (/ 1 100) = ??
« Reply #6 on: October 28, 2005, 04:38:59 PM »
That is one of the reason in lisp before doing a division verify if at least one of the arguments if a REAL... if not simply adding a zero at the end....

HTH

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (/ 1 100) = ??
« Reply #7 on: October 28, 2005, 04:42:56 PM »
Not strange at all.
eg
(+ 2147483640  10)
;=> -2147483646


??  For me...this is strange

not sure to understand... :-(

so why if i change a number...it work ?

Commande: (+ 2147483240  10)
2147483250

Commande: (+ 2147483600  10)
2147483610

Commande: (+ 2147433600  10)
2147433610

Commande: (+ 2147433680  10)
2147433690

Commande: (+ 2147433690  10)
2147433700
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (/ 1 100) = ??
« Reply #8 on: October 28, 2005, 04:48:57 PM »
Andrea, read what I said again ..
Quote
.. another is applying arithmatic operators to integers where the result is larger than the integer legal capacity.


From the AutoLISP HELP FILE
AutoLISP Developers Guide  -> Using the AutoLISP Language -> AutoLISP Basics -> AutoLISP Data Types -> Integers

Quote
Integers are whole numbers that do not contain a decimal point. AutoLISP integers are 32-bit signed numbers with values ranging from +2,147,483,647 to –2,147,483,648. (Note, however, that the getint function only accepts 16-bit numbers ranging from +32767 to -32678.) When you explicitly use an integer in an AutoLISP expression, that value is known as a constant. Numbers such as 2, –56, and 1,200,196 are valid AutoLISP integers.
.... < continues>



« Last Edit: October 28, 2005, 04:53:52 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (/ 1 100) = ??
« Reply #9 on: October 28, 2005, 05:02:28 PM »
.... before doing a division verify if at least one of the arguments if a REAL... .....

HTH

Yes Luis.

<in code> If I cant be assured that one of the values is a REAL I use the (float <variable> ) function.

eg

Code: [Select]
(setq a 20
      b (doit x y) ; We aren't sure what TYPE this will be 
.
.
.
.

      c (/ a (float b) )
)


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bob Wahr

  • Guest
Re: (/ 1 100) = ??
« Reply #10 on: October 28, 2005, 05:14:10 PM »
Code: [Select]
(setq a 20
      b (doit x y) ; We aren't sure what TYPE this will be 
.
.
.
.

      c (/ a (float b) )
)



those doits are everywhere today.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (/ 1 100) = ??
« Reply #11 on: October 28, 2005, 05:20:21 PM »
:)

I put them in just for you Bob .. and giggled as I did it.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bob Wahr

  • Guest
Re: (/ 1 100) = ??
« Reply #12 on: October 28, 2005, 05:22:22 PM »
 :-D

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (/ 1 100) = ??
« Reply #13 on: October 28, 2005, 08:12:23 PM »
Thanks...

Now..I have much work here thanks to you. :cry:


 :lmao:
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (/ 1 100) = ??
« Reply #14 on: October 28, 2005, 08:17:24 PM »
Thanks...

Now..I have much work here thanks to you. :cry:

 :lmao:

 :evil:

Yes, I do that to people sometimes  :lol:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bob Wahr

  • Guest
Re: (/ 1 100) = ??
« Reply #15 on: October 28, 2005, 08:23:04 PM »
IF they are all done the same and IF the solution is the same for all THEN you could do a simple find and replace making it less of a chore.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (/ 1 100) = ??
« Reply #16 on: October 31, 2005, 07:59:06 AM »
Yes Luis.

<in code> If I cant be assured that one of the values is a REAL I use the (float <variable> ) function.

Indeed.

OT: Shouldn't this thread be in the Vanilla / Visual LISP Forum?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst