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

bassic maths rounding off to full figure autolisp

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
The_Caddie
1176 Views, 6 Replies

bassic maths rounding off to full figure autolisp

I need to know how to do a particular equation-using lisp

 

Her goes I have 6000mm divided by distances of 610mm leaves me with 9.836065574 rectangular arrays the amount rectangular arrays has to be a full figure how can I round this of to the next full figure of 10.

 

The amount of rectangular arrays will vary pending on how long I want my wall to be so as to say the 6000mm is hardly ever the same. Unlike the 610mm which is a value set by the industry (610mm is the distance allowed in-between beams AKA: always and without exception the same)

6 REPLIES 6
Message 2 of 7
pbejse
in reply to: The_Caddie

(fix (+ 9.836065574
         (/ 9.836065574 (abs 9.836065574) 2.0)
      )
        )

 

 

Message 3 of 7
The_Caddie
in reply to: pbejse

this works fine i should leave it at that however could you give us a quick runthrough on what your example is doing so i may understand rather then just accept...

 

thanks-

 

Message 4 of 7
pbejse
in reply to: The_Caddie


@The_Caddie wrote:

could you give us a quick runthrough on what your example is doing so i may understand rather then just accept...

 

thanks-

 


The fix function will round the value to nearest smaller integer.

(fix 2.5)  --> 2

(fix 2.75) - > 2

to avoid that. what we did is throw in a factor that determines the decimal value is above or belowhalf of 1.0

( / 2.75 2.75 2.0) <-- same as  ( / 2.75 2.75)  ( / 1.0 2.0)

0.5

add to original number

(+ 2.75 0.5)

3.25

(fix 3.25)

3 <-- still the nearest smaller integer

 

HTH

 

 

 


 

Message 5 of 7
Kent1Cooper
in reply to: The_Caddie


@The_Caddie wrote:

.... 

Her goes I have 6000mm divided by distances of 610mm leaves me with 9.836065574 rectangular arrays the amount rectangular arrays has to be a full figure how can I round this of to the next full figure of 10.

 

....the 610mm which is a value set by the industry (610mm is the distance allowed in-between beams AKA: always and without exception the same)


Put "round" or "rounding" or "round up" into the Search window, and you will find many examples of how to do this, with varying degrees of explanation, rounding to the nearest integer value or to the nearest multiple of some value such as your 610, some that round to the nearest value in whichever direction is closer and some that only round up, and other differences.

Kent Cooper, AIA
Message 6 of 7
The_Caddie
in reply to: pbejse

I’m sorry I have to com back on this because its been pointed out through my testing of the lisp that my situation is dependant on a factor of whether the rounding of is over or below x.5

 

Anything below x.5 (example 10.342) should round down to the nearest and anything above x.5 should (example 67.567round up. As for items that fall exactly on x.5 (example 2978.5) they should round down also

 

(X representing any number before the decimal place).

Message 7 of 7
pbejse
in reply to: The_Caddie


@The_Caddie wrote:

 

Anything below x.5 (example 10.342) should round down to the nearest and anything above x.5 should (example 67.567round up. As for items that fall exactly on x.5 (example 2978.5) they should round down also

 


Quick fix

(if (eq (rem num (fix num)) 0.5) (fix num)
 (fix (+ num
          (/ num (abs num) 2.0)
       )
         )
  )

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

Post to forums  

Autodesk Design & Make Report

”Boost