Uh oh!
There was an error while loading. Please reload this page.
Add support for hexadecimal, octal and binary values - #40
Conversation
jubianchi
commented
Mar 7, 2016
Of course, tests are green: The only drawbacks of those notation are they are not compatible with PHP itself so we cannot directly add them to unit tests :/ We could support native syntax (as @Metalaka pointed out in #39 - http://php.net/manual/en/language.types.integer.php) but we would have to forbid constants/ids starting with digits so that we can use |
CircleCode
commented
Mar 7, 2016
this seems weird, but just thinking out loud: what about allowing constants starting by any digit other than |
jubianchi
commented
Mar 7, 2016
@CircleCode why not :)
Must also apply to ids then ;) |
CircleCode
commented
Mar 7, 2016
maybe the question is "why did we want to allow constants starting by digits?" → the answer could help to chose one of the possible solutions amongst
|
jubianchi
commented
Mar 8, 2016
When talking with @Hywan about supporting constants/ids starting with digits, I talked about "side effects": this one is a side-effects. It prevents us from implementing something interesting with a generic notation. My opinion is: let's close #39 and change constant names in #38 to something like |
CircleCode
commented
Mar 8, 2016
I share @jubianchi 's opinion. |
Hywan
commented
Mar 8, 2016
See my comment in #39. |
Metalaka
commented
Mar 8, 2016
@jubianchi@CircleCode 👍 |
Hywan
commented
Mar 9, 2016
👍 |
| new LUT\Sampler\Random() | ||
| ), | ||
| 9 | ||
| 7 |
There was a problem hiding this comment.
I changed this value because with 9 the test suite generated more than a million expressions and I could not reach the end of the test... way tooooooo long :)
There was a problem hiding this comment.
I tried with 8 which produce a reasonable test suite (~200 seconds AFAIR) but ended up getting the #42 bug :/
jubianchi
commented
Mar 9, 2016
|
| } elseif ('id' === $token) { | ||
| return $value; | ||
| } elseif ('binary' === $token || 'hex' === $token || 'octal' === $token) { | ||
| $out = (float) eval('return ' . $value . ';'); |
There was a problem hiding this comment.
the only way to make them work is by trimming litterals before passing them to *dec : bindec(str_replace('0b', '', $binary));
There was a problem hiding this comment.
So do it. That's by far faster than using an eval. Also, eval is not caught by the opcode cache.
jubianchi
commented
Mar 11, 2016
thanks for the review. Updates will be done today |
Hywan
commented
Mar 11, 2016
❤️ |
jubianchi
commented
Mar 11, 2016
@hoaproject/hoackers need review :) |
Users can now use three new notations: * `0x539` for hexadecimal values * `0b101010` for binary values * `052` for octal values We can also mix them in expressions: ``` - ( 0b101010 * ( 0x539 / -052 ) ) / 100 ``` The result here will be `13.37`
| ) | ||
| ->then | ||
| ->object($compiler->parse($hexadecimalNumber)) | ||
| ->isInstanceOf('Hoa\Compiler\Llk\TreeNode') |
There was a problem hiding this comment.
You can check the ID and the value of the token (resp. token and hexadecimal).
Same for subsequent test cases.
Review done. Need a little bit more corrections :-). |
Hywan
commented
May 9, 2016
And some test cases for overflows. |
Users can now use three new notations:
\x5390x539for hexadecimal values\b1010100b101010for binary values\052052for octal valuesWe can also mix them in expressions:
- ( \b101010 * ( \x539 / -\052 ) ) / 100- ( 0b101010 * ( 0x539 / -052 ) ) / 100The result here will be
13.37