Skip to content

Commit

Permalink
LDEV-5194 - make the compiler independent from the precisemath setting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 13, 2024
1 parent 3d5667c commit 45b8f8a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public LitNumber createLitNumber(Number n) {

@Override
public LitNumber createLitNumber(Number n, Position start, Position end) {
return new LitNumberImpl(this, n instanceof BigDecimal ? (BigDecimal) n : BigDecimal.valueOf(n.doubleValue()), start, end);
return new LitNumberImpl(this, n, start, end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;

import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.op.Caster;
import lucee.transformer.Factory;
import lucee.transformer.Position;
Expand Down Expand Up @@ -61,8 +60,7 @@ public LitBooleanImpl(Factory f, boolean b, Position start, Position end) {

@Override
public Number getNumber(Number defaultValue) {
if (ThreadLocalPageContext.preciseMath(null)) return b ? BigDecimal.ONE : BigDecimal.ZERO;
return Caster.toDouble(b);
return b ? BigDecimal.ONE : BigDecimal.ZERO;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ public class LitNumberImpl extends ExpressionBase implements LitNumber, ExprNumb
}

private String number;
private BigDecimal bd;
private Number nbr;

public LitNumberImpl(Factory f, String number, Position start, Position end) {
super(f, start, end);
this.number = number;
}

public LitNumberImpl(Factory f, BigDecimal bd, Position start, Position end) {
public LitNumberImpl(Factory f, Number nbr, Position start, Position end) {
super(f, start, end);
this.bd = bd;
this.number = Caster.toString(bd);

this.nbr = nbr;
this.number = Caster.toString(nbr);
}

@Override
Expand Down Expand Up @@ -96,14 +95,13 @@ public Boolean getBoolean(Boolean defaultValue) {
}

public BigDecimal getBigDecimal() throws CasterException {
if (bd == null) bd = Caster.toBigDecimal(number);
return bd;
if (nbr == null) return Caster.toBigDecimal(number);
return Caster.toBigDecimal(nbr);
}

@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();

// are we within a method not providing PageContext as first argument?
boolean firstIsPC = ASMUtil.isFirstArgumentPageContext(bc);

Expand All @@ -116,7 +114,8 @@ public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException
}
return Types.DOUBLE_VALUE;
}
Long l = justNumberDigits(number) ? Caster.toLong(number, null) : null;
// we only take length 18 to avoid edge cases
Long l = number.length() < 18 && justNumberDigits(number) ? Caster.toLong(number, null) : null;

if (l != null && Caster.toString(l).equals(number)) {
if (firstIsPC) adapter.loadArg(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.StringUtil;
import lucee.runtime.config.ConfigPro;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.op.Caster;
import lucee.transformer.Factory;
import lucee.transformer.Position;
Expand Down Expand Up @@ -140,9 +139,7 @@ private static ExprString _toExpr(Factory factory, String str) {

@Override
public Number getNumber(Number defaultValue) {
Number res;
if (ThreadLocalPageContext.preciseMath(null)) res = Caster.toBigDecimal(str, null);
else res = Caster.toDouble(getString(), null);
Number res = Caster.toBigDecimal(str, null);
if (res != null) return res;
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.math.BigDecimal;

import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.op.Caster;
import lucee.transformer.Factory;
import lucee.transformer.Position;
Expand Down Expand Up @@ -78,8 +77,7 @@ public boolean getBooleanValue() {

@Override
public Number getNumber(Number defaultValue) {
if (ThreadLocalPageContext.preciseMath(null)) return b ? BigDecimal.ONE : BigDecimal.ZERO;
return Caster.toDouble(b);
return b ? BigDecimal.ONE : BigDecimal.ZERO;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package lucee.transformer.interpreter.literal;

import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.op.Caster;
import lucee.transformer.Factory;
import lucee.transformer.Position;
Expand Down Expand Up @@ -41,9 +40,7 @@ public String getString() {

@Override
public Number getNumber(Number defaultValue) {
Number res;
if (ThreadLocalPageContext.preciseMath(null)) res = Caster.toBigDecimal(str, null);
else res = Caster.toDouble(getString(), null);
Number res = Caster.toBigDecimal(str, null);
if (res != null) return res;
return defaultValue;
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.207-SNAPSHOT"/>
<property name="version" value="6.2.0.208-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.207-SNAPSHOT</version>
<version>6.2.0.208-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 45b8f8a

Please sign in to comment.