What do u think? My own floor/ceil func...
Posted on 1998-09-20
I am out of points so pls. do try to help... :(
I am writing my own floor/ceil implementation without using those from 'math.h' lib and I want your opinions on the efficiency and possible bugs/flaws on my coding design...
I am using macros..
/* conversion from float/double to nearest integer */
#define floor(a) (((a - (int)a)>0)? (int)a:a)
#define ceil(a) (((a - (int)a)>0)? ((int)a + 1):a)
1. if I key in a = 22.3, (a-(int)a) = 22.3 - 22=0.3 > 0
so I would ret (int)a = 22 ( for Floor() )
2. if I key in a = 22.3, (a-(int)a) = 22.3 - 22.0 = 0.3
>0 so I would ret ((int)a+1) = 22+1 = 23 (for Ceil())
I am not sure whether the syntax is ok as I haven't tested it yet... :)