09 November 2008

the 42nd law of parenting (a theorem)

aka "the law of the rabit pellet diaper."

The stench is inversely proportional to the volume.

I'm sure my fellow parents know *precisely* what I'm talking about... from the reaking rabbit pellets, to virtually scentless triple blow-outs that you didn't even know were there from a distance.

04 November 2008

php fails at the maths

ugh. I've spent the last few hours fighting a bug that's been driving me up the wall.


marchhair:~ cabbey$ php
<?
$d = 1.59;
$s = (double) "1.59";
if ($d == $s) {
  echo "$d and $s are equal\n";
} else {
  echo "phpFAILS, $d and $s aren't equal\n";
}
?>
1.59 and 1.59 are equal
marchhair:~ cabbey$ php
<?
$d = 0.99 + 0.60;
$s = (double) "1.59";
if ($d == $s) {
  echo "$d and $s are equal\n";
} else {
  echo "phpFAILS, $d and $s aren't equal\n";
}
?>
phpFAILS, 1.59 and 1.59 aren't equal


So, OK, I get that due to the limitation of floating point accuracy sometimes weird shit happens... like getting 7.9999... when you expected 8.0. But look at the output, they're clearly similar enough that they both render as 1.59... but they're different enough to cause a comparison to fail.


ARGH!


In the end, I used strcmp. :(

Labels: , , , , ,