ID: 40996 Updated by: [EMAIL PROTECTED] Reported By: ehanneken at pobox dot com Status: Open Bug Type: Documentation problem PHP Version: Irrelevant New Comment:
I wonder whether or not we should have the formal grammar at all. We're not trying to teach people how to parse floating point numbers: just tell them how to write them out. Plus, it's not even stated what the grammar is written in! (it's certainly not EBNF, not a Perl regexp due to extra spacing, what is it?) The formal grammar was added by jeroen in v1.21 as a comment, which goba turned into an actual section later on. The PHP parser doesn't "natively" recognize signs to the float syntax: so +-+-+-+3.4, while very strange, does work with the PHP parser. Instead, we're really using + and - operator to change the sign of the float. I.e. -4.2 == -(4.2) to the PHP parser For the average Joe, I don't think this distinction makes much difference though. Finally, the revised grammar has a bug: it doesn't include "unsigned" exponential non-decimal numbers, eg. 4e4. Previous Comments: ------------------------------------------------------------------------ [2007-04-04 15:03:32] ehanneken at pobox dot com There was a bug in my revised grammar, too. How about this? ULNUM [0-9]+ SLNUM [+-]{ULNUM} DNUM [+-]?(([0-9]*[\.]{ULNUM}) | ({ULNUM}[\.][0-9]*)) EXPONENT_DNUM ( ({SLNUM} | {DNUM}) [eE][+-]? {ULNUM}) ------------------------------------------------------------------------ [2007-04-04 15:03:12] ehanneken at pobox dot com There was a bug in my revised grammer, too. How about this? ULNUM [0-9]+ SLNUM [+-]{ULNUM} DNUM [+-]?(([0-9]*[\.]{ULNUM}) | ({ULNUM}[\.][0-9]*)) EXPONENT_DNUM ( ({SLNUM} | {DNUM}) [eE][+-]? {ULNUM}) ------------------------------------------------------------------------ [2007-04-04 14:56:00] ehanneken at pobox dot com Description: ------------ According to the manual (http://www.php.net/manual/en/language.types.float.php), the following grammar specifies floating point numbers: LNUM [0-9]+ DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*) EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM}) This leaves out signed numbers. The grammar should be written as something like ULNUM [0-9]+ SLNUM [+-]{ULNUM} DNUM [+-]?(([0-9]*[\.]{ULNUM}) | ({ULNUM}[\.][0-9]*)) EXPONENT_DNUM [+-]?( ({ULNUM} | {DNUM}) [eE][+-]? {ULNUM}) Reproduce code: --------------- echo gettype(-3.14) . "\n"; echo gettype(+3.14); Expected result: ---------------- double double Actual result: -------------- double double ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40996&edit=1