Re: floor()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Well, not exactly adding 1, because if the argument is integer (after the
division) you'll get a result off by 1. These issues are treated in my
package General Functions, where one can find FloorTowardsZero, Ceil, etc.
routines. For example, Ceil(a) is -floor(-a).
----- Original Message -----
From: <a.tammer at hetnet.nl>
To: "EUforum" <EUforum at topica.com>
Subject: floor()



for those among us, who haven't done any floor(-x [/y] ) yet,
make a note that floor(-1.5) yields -2. this is of course fully
correct because -2 is the next lower to -1. however, you might
expect the floor()ing done towards ZERO, which in calculations
would be easier. So be aware, when doing arithmetics on the
results to add 1 to the floor(-x/y) result.

floor(-1.5) * 2 + 2 * remainder(-1.5,1)   yields -5

i tripped over it while working on icd-math.

antoine tammer

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu