note 107471 added to language.operators.comparison

From: Date: Sat, 11 Feb 2012 05:12:58 +0000
Subject: note 107471 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-186065@lists.php.net to get a copy of this message
Regarding post [sven dot heyll at web dot de 05-Dec-2004 01:19]: the function isn't valid for all cases (e.g. adding six additional lines to the end results in "not equal" and "not equal" being output, the opposite of the truth) -- <?php //! compare two floating point values, return true if they are equal //! (enough) or false otherwise function float_equal($f1, $f2) { return ($f1 > $f2) ? (false) : (!($f1 < $f2)); } // compare floats $f1 = 0.037; $f2 = 1000387.978; echo "$f1 and $f2 are ".(float_equal($f1,$f2)?("equal"):("not equal"))."<br />"; $f1 = 0.3; $f2 = 0.3; echo "$f1 and $f2 are ".(float_equal($f1,$f2)?("equal"):("not equal"))."<br />"; $f1 = 0.3; $f2 = 0.1 * 3; echo "$f1 and $f2 are ".(float_equal($f1,$f2)?("equal"):("not equal"))."<br />"; $f1 = 0.1 * 3; $f2 = 0.3; echo "$f1 and $f2 are ".(float_equal($f1,$f2)?("equal"):("not equal"))."<br />"; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 72.219.151.91 ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/107471 Del: integrated -- https://master.php.net/note/delete/107471/integrated Del: useless -- https://master.php.net/note/delete/107471/useless Del: bad code -- https://master.php.net/note/delete/107471/bad+code Del: spam -- https://master.php.net/note/delete/107471/spam Del: non-english -- https://master.php.net/note/delete/107471/non-english Del: in docs -- https://master.php.net/note/delete/107471/in+docs Del: other reasons-- https://master.php.net/note/delete/107471 Reject -- https://master.php.net/note/reject/107471 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186065) next »