Floor and Ceil in C – Objective C snippet

Objective C snippet to understand floor and ceil C functions:

It is interesting, that if you divide for instance ceil(9 / 2) you will get 4. But if you divide ceil(9 / 2.0) you will get 5 as expected. I struggled with this issue a little, while trying to calculate item height dynamically for iPhone 5 and iPhone 3-4 in my UICollectionView this way:

where

I guess, that when you divide 9/2 you get 4 as a result (integer division). When you divide 9/2.0 you get 4.5 which is “ceiled” correctly.