use of php.runtime.annotation.Runtime.Immutable in project jphp by jphp-compiler.
the class JsonFunctions method json_encode.
@Immutable
public static String json_encode(Memory memory, int options) {
GsonBuilder builder;
if (options != 0) {
MemorySerializer serializer = new MemorySerializer();
builder = JsonExtension.createGsonBuilder(serializer);
if ((options & JsonConstants.JSON_PRETTY_PRINT) == JsonConstants.JSON_PRETTY_PRINT) {
builder.setPrettyPrinting();
}
if ((options & JsonConstants.JSON_HEX_TAG) != JsonConstants.JSON_HEX_TAG) {
builder.disableHtmlEscaping();
}
if ((options & JsonConstants.JSON_FORCE_OBJECT) == JsonConstants.JSON_FORCE_OBJECT) {
serializer.setForceObject(true);
}
if ((options & JsonConstants.JSON_NUMERIC_CHECK) == JsonConstants.JSON_NUMERIC_CHECK) {
serializer.setNumericCheck(true);
}
} else {
builder = JsonExtension.DEFAULT_GSON_BUILDER;
}
Gson gson = builder.create();
return gson.toJson(memory);
}
use of php.runtime.annotation.Runtime.Immutable in project jphp by jphp-compiler.
the class MathFunctions method pow.
@Immutable
public static Memory pow(Memory base, Memory exp) {
Memory realBase = base.toNumeric();
Memory realExp = exp.toNumeric();
if (realBase.type == Memory.Type.INT && realExp.type == Memory.Type.INT) {
double result = Math.pow(realBase.toLong(), realExp.toLong());
if (result > Long.MAX_VALUE) {
return DoubleMemory.valueOf(result);
}
return LongMemory.valueOf((long) result);
} else {
return new DoubleMemory(Math.pow(base.toDouble(), exp.toDouble()));
}
}
Aggregations