|
20 | 20 |
|
21 | 21 | import java.math.BigDecimal; |
22 | 22 | import java.math.BigInteger; |
| 23 | +import java.math.MathContext; |
23 | 24 | import java.text.CharacterIterator; |
24 | 25 | import java.text.StringCharacterIterator; |
25 | 26 | import java.util.Stack; |
@@ -83,7 +84,7 @@ public void prevChar() { |
83 | 84 | } |
84 | 85 |
|
85 | 86 | static final char[] VALID_HEX_CHAR = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'a', 'B', 'b', 'C', |
86 | | - 'c', 'D', 'd', 'E', 'e', 'F', 'f' }; |
| 87 | + 'c', 'D', 'd', 'E', 'e', 'F', 'f' }; |
87 | 88 |
|
88 | 89 |
|
89 | 90 | public boolean isValidHexChar(char ch) { |
@@ -237,21 +238,23 @@ else if (hasDot) { |
237 | 238 | || this.peek == 'M' || this.peek == 'N'); |
238 | 239 | Number value; |
239 | 240 | if (isBigDecimal) { |
240 | | - value = getDecimalValue(sb); |
| 241 | + value = |
| 242 | + new BigDecimal(this.getBigNumberLexeme(sb), |
| 243 | + (MathContext) AviatorEvaluator.getOption(Options.MATH_CONTEXT)); |
241 | 244 | } |
242 | 245 | else if (isBigInt) { |
243 | | - String lexeme = this.getBigNumberLexeme(sb); |
244 | | - value = new BigInteger(lexeme); |
| 246 | + value = new BigInteger(this.getBigNumberLexeme(sb)); |
245 | 247 | } |
246 | 248 | else if (hasDot) { |
247 | | - boolean alwaysUseDecimalAsDouble = AviatorEvaluator |
248 | | - .getOption(Options.ALWAYS_USE_DOUBLE_AS_DECIMAL); |
249 | | - if (alwaysUseDecimalAsDouble) { |
250 | | - value = new BigDecimal(sb.toString(), |
251 | | - AviatorEvaluator.getMathContext()); |
252 | | - } else { |
253 | | - value = dval; |
254 | | - } |
| 249 | + boolean alwaysUseDecimalAsDouble = AviatorEvaluator.getOption(Options.ALWAYS_USE_DOUBLE_AS_DECIMAL); |
| 250 | + if (alwaysUseDecimalAsDouble) { |
| 251 | + value = |
| 252 | + new BigDecimal(sb.toString(), |
| 253 | + (MathContext) AviatorEvaluator.getOption(Options.MATH_CONTEXT)); |
| 254 | + } |
| 255 | + else { |
| 256 | + value = dval; |
| 257 | + } |
255 | 258 | } |
256 | 259 | else { |
257 | 260 | // if the long value is out of range,then it must be negative,so |
@@ -318,15 +321,6 @@ else if (hasDot) { |
318 | 321 | return token; |
319 | 322 | } |
320 | 323 |
|
321 | | - |
322 | | - private Number getDecimalValue(StringBuffer sb) { |
323 | | - Number value; |
324 | | - String lexeme = this.getBigNumberLexeme(sb); |
325 | | - value = new BigDecimal(lexeme, AviatorEvaluator.getMathContext()); |
326 | | - return value; |
327 | | - } |
328 | | - |
329 | | - |
330 | 324 | private String getBigNumberLexeme(StringBuffer sb) { |
331 | 325 | String lexeme = sb.toString(); |
332 | 326 | lexeme = lexeme.substring(0, lexeme.length() - 1); |
|
0 commit comments