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)
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
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-
@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
@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.
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).
@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)
)
)
)