use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class BCMathFunctions method bcmod.
public static Memory bcmod(Memory left, Memory modus) {
BigDecimal base = toBigDecimal(left).setScale(0, RoundingMode.DOWN);
BigDecimal mod = toBigDecimal(modus).setScale(0, RoundingMode.DOWN);
if (mod.compareTo(BigDecimal.ZERO) == 0) {
return Memory.NULL;
}
return new StringMemory(base.remainder(mod, MathContext.UNLIMITED).toString());
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class BCMathFunctions method bcmul.
public static Memory bcmul(Environment env, Memory left, Memory right, int scale) {
BigDecimal bd1 = toBigDecimal(left);
BigDecimal bd2 = toBigDecimal(right);
BigDecimal bd = bd1.multiply(bd2);
// odd php special case for 0, scale is ignored:
if (bd.compareTo(BigDecimal.ZERO) == 0) {
if (scale > 0)
return new StringMemory("0.0");
else
return new StringMemory("0");
}
bd = bd.setScale(scale, RoundingMode.DOWN);
bd = bd.stripTrailingZeros();
return new StringMemory(bd.toPlainString());
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class BCMathFunctions method bcsqrt.
public static Memory bcsqrt(Environment env, Memory operand, int scale) {
BigDecimal value = toBigDecimal(operand);
int compareToZero = value.compareTo(BigDecimal.ZERO);
if (compareToZero < 0) {
return Memory.NULL;
} else if (compareToZero == 0) {
return new StringMemory("0");
}
int compareToOne = value.compareTo(BigDecimal.ONE);
if (compareToOne == 0)
return new StringMemory("1");
int cscale;
BigDecimal initialGuess;
if (compareToOne < 1) {
initialGuess = BigDecimal.ONE;
cscale = value.scale();
} else {
BigInteger integerPart = value.toBigInteger();
int length = integerPart.toString().length();
if ((length % 2) == 0)
length--;
length /= 2;
initialGuess = BigDecimal.ONE.movePointRight(length);
cscale = Math.max(scale, value.scale()) + 2;
}
BigDecimal guess = initialGuess;
BigDecimal lastGuess;
for (int iteration = 0; iteration < 50; iteration++) {
lastGuess = guess;
guess = value.divide(guess, cscale, RoundingMode.DOWN);
guess = guess.add(lastGuess);
guess = guess.divide(DECIMAL_TWO, cscale, RoundingMode.DOWN);
if (lastGuess.equals(guess)) {
break;
}
}
value = guess;
value = value.setScale(scale, RoundingMode.DOWN);
return new StringMemory(value.toPlainString());
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class ReflectionClass method setEntity.
public ReflectionClass setEntity(ClassEntity entity) {
this.entity = entity;
getProperties().put("name", new StringMemory(entity.getName()));
return this;
}
use of php.runtime.memory.StringMemory in project jphp by jphp-compiler.
the class ReflectionExtension method setExtension.
public void setExtension(Extension extension) {
this.extension = extension;
getProperties().put("name", new StringMemory(extension.getName()));
}
Aggregations