forked from Mirror/wren
Support positive sign in scientific notation (#706)
* Support positive sign in scientific notation * Add exponent with positive sign to docs
This commit is contained in:
@ -19,6 +19,7 @@ Like other scripting languages, Wren has a single numeric type:
|
||||
double-precision floating point. Number literals look like you expect coming
|
||||
from other languages:
|
||||
|
||||
|
||||
<pre class="snippet">
|
||||
0
|
||||
1234
|
||||
@ -26,6 +27,9 @@ from other languages:
|
||||
3.14159
|
||||
1.0
|
||||
-12.34
|
||||
0.0314159e02
|
||||
0.0314159e+02
|
||||
314.159e-02
|
||||
</pre>
|
||||
|
||||
Numbers are instances of the [Num][] class.
|
||||
|
||||
@ -762,8 +762,11 @@ static void readNumber(Parser* parser)
|
||||
// See if the number is in scientific notation.
|
||||
if (matchChar(parser, 'e') || matchChar(parser, 'E'))
|
||||
{
|
||||
// Allow a negative exponent.
|
||||
// Allow a single positive/negative exponent symbol.
|
||||
if(!matchChar(parser, '+'))
|
||||
{
|
||||
matchChar(parser, '-');
|
||||
}
|
||||
|
||||
if (!isDigit(peekChar(parser)))
|
||||
{
|
||||
|
||||
@ -7,3 +7,4 @@ System.print(2.55e-2 is Num) // expect: true
|
||||
System.print(x is Num) // expect: true
|
||||
System.print(-2.55e2) // expect: -255
|
||||
System.print(-25500e-2) // expect: -255
|
||||
System.print(2.55e+2) // expect: 255
|
||||
|
||||
@ -0,0 +1 @@
|
||||
var x = 1e+-01 // expect error
|
||||
Reference in New Issue
Block a user