Hi,

Yesterday I sent Alex a couple of fixed-point functions, 'floor' and 'ceil', asking if he had any comments. He made me aware that I hadn't thought of negative input values. Here are my improved versions:

(de floor (X)
        (let R (% X 1.0)
                (if (lt0 R) (- X R 1.0) (- X R)) ) )

(de ceil (X)
        (let R (% X 1.0)
                (if (gt0 R) (+ (- X R) 1.0) (- X R)) ) )

Here are some examples, with *Scl set to 4:

: (floor 12.34)
-> 120000
: (floor -12.34)
-> -130000
: (floor 12.0)
-> 120000
: (floor -12.0)
-> -120000
: (ceil 12.34)
-> 130000
: (ceil -12.34)
-> -120000
: (ceil 12.0)
-> 120000
: (ceil -12.0)
-> -120000


/Jon

Reply via email to