ID: 19733 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: Math related Operating System: Windows 2000 PHP Version: 4.2.3 New Comment:
Interesting catch. The relevant code looks as following: for (i = Z_STRLEN_P(arg); i > 0; i--) { c = *s++; digit = (c >= '0' && c <= '9') ? c - '0' : (c >= 'A' && c <= 'Z') ? c - 'A' + 10 : (c >= 'a' && c <= 'z') ? c - 'a' + 10 : base; if (digit >= base) continue; switch (mode) { case 0: /* Integer */ onum = num; num = num * base + digit; fprintf(stderr, "num = %d, onum = %d\n", num, onum); if (num > onum) break; /* No overflow, continue */ fnum = onum; mode = 1; /* fall-through */ case 1: /* Float */ fnum = fnum * base + digit; } } from ext/standard/math.c ( _php_math_basetozval ). This code assumed that an overflow also occured when the newer 'num' == 'onum'. "A" fix would be to change the comparison to be ">=" instead of ">" . But I don't know the code well enough, someone else needs to check this toroughly. Previous Comments: ------------------------------------------------------------------------ [2002-10-03 05:33:36] [EMAIL PROTECTED] hexdec('012345') should return int(74565), but instead it returns float(74565), contrary to the documentation. This happens for all numbers in strings I've tested that begin with 0, which does not include non-hexadecimal characters which are taken to be 0, eg, hexdec('q12345') returns int. (Fixing the problem by casting the result to an (int) works fine. It originally catched me out when I used array_flip on an array of results, which demands integer or string keys.) I'm not sure what the configure line is, but it's just a regular install from the downloaded executable binary, with no extra modules loaded. Since maths functions are in the PHP core, it hopefully won't matter. Thanks Andrew Alderwick, United Kingdom ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19733&edit=1