Bug of the moment 2008-02-28
As part of my usual mental thumb twiddling when bored, I just confirmed to myself that some code I’m writing did not yet check for out-of-range image numbers in a photo gallery:
Wait … “-0”? Minus nought? That shouldn’t happen.
I’m calculating the number of the gallery page that the image’s thumbnail appears on, and I didn’t write any code to output minus signs, so, surely not … ’Fraid so. In PHP, there is a bug where a calculation of the following variety:
echo ceil(-1 / 10);
will return -0. D’oh.
For the record, this is PHP 5.2.5. I then added, “Cue Perl gloating from you-know-who” but then, I thought, no, surely not …
[rootbeer]$ perl -e "use POSIX; print ceil(-1 / 10) . \"\r\n\";" -0
Posted 28th February 2008 – Comments and questions?