Hello:
working with the ROUND function I can see that it does not round well for example 5.5 (it does 5 and not 6) and any number ending in .5.
CLIPS (6.31 6/12/19)
CLIPS> (round 5.5)
5
CLIPS> (round 5.51)
6
CLIPS> (round 5.49)
5
CLIPS>
To try to save this I made a function but when I perform it I see this:
I don't understand where the error is?
if I repeat the same function but changing the numbers, if it works for me.
CLIPS (6.31 6/12/19)
CLIPS> (deffunction redondeo
(?numero)
(if (and(>=(- ?numero (integer ?numero)) 0)
(<= (- ?numero (integer ?numero)) 0.04))then (printout t (integer ?numero))))
CLIPS> (redondeo 5.04)
FALSE
CLIPS> (redondeo 3.04)
FALSE
CLIPS> (redondeo 3.03)
3
CLIPS> (deffunction redondeo
(?numero)
(if (and(>=(- ?numero (integer ?numero)) 0.05)
(<= (- ?numero (integer ?numero)) 0.14))then (printout t (integer ?numero))))
CLIPS> (redondeo 0.14)
0
CLIPS> (redondeo 6.14)
6
(round 5.500001) -> 6
(round 5.499999) -> 5
For me, the round function works.
The round function rounds its only argument (which should be a numeric expression) toward the closest integer. If the argument is exactly between two integers, it is rounded down.