From 34b07378fd3c9d89461b1f32155cb3cb36af8802 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Thu, 10 Apr 2025 14:51:36 -0700 Subject: [PATCH] Fix 1e parsing Fix 1e5, 1e-5 evaluated as Infinity (https://github.com/HaxeFoundation/hscript/pull/132) --- TestHScript.hx | 4 ++++ hscript/Parser.hx | 2 ++ 2 files changed, 6 insertions(+) diff --git a/TestHScript.hx b/TestHScript.hx index 72682da..a20dd75 100644 --- a/TestHScript.hx +++ b/TestHScript.hx @@ -33,6 +33,10 @@ class TestHScript extends TestCase { assertScript("- 123",-123); assertScript("1.546",1.546); assertScript(".545",.545); + assertScript("1e5",100000); + assertScript("1.2e2",120); + assertScript("100e-2",1); + assertScript("1.2e-1",0.12); assertScript("'bla'","bla"); assertScript("null",null); assertScript("true",true); diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 0361843..73b0f81 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -1943,6 +1943,8 @@ class Parser { } if( pow == null ) invalidChar(char); + if( exp == 0 ) + exp = 10; return TConst(CFloat((Math.pow(10, pow) / exp) * n * 10)); case ".".code: if( exp > 0 ) {