Bug #16036 Updated: in_array() with pow()

From: Date: Wed, 13 Mar 2002 11:55:03 +0000
Subject: Bug #16036 Updated: in_array() with pow()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-2376@lists.php.net to get a copy of this message
ID: 16036 Updated by: rasmus@php.net Reported By: goodman888@hongkong.com Status: Bogus Bug Type: *Math Functions Operating System: Solaris PHP Version: 4.1.0 New Comment: The bug database is not the place to ask questions like this. And like I mentioned, just convert to a string: $a = pow(2,31); $b = array("$a"); echo in_array(2147483648, $b); That prints 1 Previous Comments: ------------------------------------------------------------------------ [2002-03-13 06:47:58] goodman888@hongkong.com Can anyone give me a "workable" version? I've tried even to convert all numbers into integers, floats or whatever. It still does not work. ------------------------------------------------------------------------ [2002-03-13 06:23:40] rasmus@php.net This is a variation of the commonly asked floating point number comparison question. At numbers beyond 2^31-1 pow() returns a float. Doing exact comparisons of an integer against a floating point value in any computer language is tricky because of the way floating point numbers are represented. You could make sure your precision is set the way you want and convert to a string, or apply a fuzz factor. ------------------------------------------------------------------------ [2002-03-13 06:20:57] mfischer@php.net var_dump() _ONLY_ works on variables. ------------------------------------------------------------------------ [2002-03-13 06:15:21] goodman888@hongkong.com $a = pow(2,31); $b = array($a); var_dump( in_array(2147483648, $b)); $b = array(2147483648); var_dump( in_array(2147483648, $b)); // this is the result. how come there are different? bool(false) bool(true) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16036&edit=1

« previous php.bugs (#2376) next »