Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/com/ql/util/express/parse/ExpressParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ public List<ExpressNode> transferWord2ExpressNode(ExpressPackage rootExpressPack
tempWord = tempWord.substring(0, tempWord.length() - 1);
objectValue = Long.valueOf(tempWord);
} else {
long tempLong = Long.parseLong(tempWord);
long tempLong;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方转成double可能更合适,基于一下两点:

  1. 2e-2,这个是0.02,转成long直接是0了
  2. 科学计数法标识的数值可以很大,超过long的最大值。

if (tempWord.indexOf("e") >=0 || tempWord.indexOf("E") >=0) {
tempLong = Double.valueOf(tempWord).longValue();
} else {
tempLong = Long.parseLong(tempWord);
}
if (tempLong <= Integer.MAX_VALUE && tempLong >= Integer.MIN_VALUE) {
tempType = nodeTypeManager.findNodeType("CONST_INTEGER");
objectValue = (int)tempLong;
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/ql/util/express/bugfix/ScientificNumberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ql.util.express.bugfix;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
* created by jiwenxing on 2022/5/12
*/
public class ScientificNumberTest {

static List<String> express = new ArrayList<>();
static {
express.add("2e2==200");
express.add("2E2==200");
express.add("2.0e2==200");
express.add("2.0E2==200");
}

@Test
public void testFunction() throws Exception {
ExpressRunner runner = new ExpressRunner();
IExpressContext<String, Object> context = new DefaultContext<>();
for (String exp: express) {
Object result = runner.execute(exp, context, null, false, false);
System.out.println(exp + ": " + result);
Comment thread
jiwenxing marked this conversation as resolved.
Outdated
assert ((Boolean)result);
}
}
}