On 2016-05-09 7:54 PM, Rowan Worth wrote: > On 10 May 2016 at 08:31, Darren Duncan <darren at darrenduncan.net> wrote: > >> The Ceiling function is not that simple, unless you know that your rank >> and outOf are always non-negative numbers. If they might be negative, you >> would -1 rather than +1 when the result is negative. -- Darren Duncan >> > > Yeah you can't always add one. But you never need to subtract one - ceil > always rounds towards positive infinity which is equivalent to integer > truncation over the range of negative reals. > > I can't see a better way to implement ceil/floor in sqlite than using an > int cast to truncate.
Yeah, actually. So if we assume casting to an integer will always truncate aka round towards zero, then the answer is to add 1 to the casted amount if and only if the real percentage is positive and doesn't equal the cast amount. -- Darren Duncan