use of php.runtime.memory.DoubleMemory in project jphp by jphp-compiler.
the class DateFunctions method microtime.
public static Memory microtime(boolean getAsFloat) {
double now = System.currentTimeMillis() / 1000.0;
int s = (int) now;
return getAsFloat ? new DoubleMemory(now) : new StringMemory((Math.round((now - s) * 1000) / 1000) + " " + s);
}
use of php.runtime.memory.DoubleMemory 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()));
}
}
use of php.runtime.memory.DoubleMemory in project jphp by jphp-compiler.
the class MemoryDeserializer method convert.
protected Memory convert(JsonElement json, int depth) {
if (depth > maxDepth)
throw new MaxDepthException();
if (json.isJsonNull())
return Memory.NULL;
if (json.isJsonPrimitive()) {
JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive();
if (jsonPrimitive.isString())
return StringMemory.valueOf(jsonPrimitive.getAsString());
else if (jsonPrimitive.isBoolean())
return jsonPrimitive.getAsBoolean() ? Memory.TRUE : Memory.FALSE;
else if (jsonPrimitive.isNumber()) {
Memory l = StringMemory.toLong(jsonPrimitive.getAsString());
if (l != null)
return l;
else
return new DoubleMemory(json.getAsDouble());
}
return Memory.NULL;
} else if (json.isJsonArray()) {
ArrayMemory array = new ArrayMemory();
for (JsonElement el : json.getAsJsonArray()) array.add(convert(el, depth + 1).toImmutable());
return array.toConstant();
} else if (json.isJsonObject()) {
JsonObject jsonObject = json.getAsJsonObject();
StdClass stdClass = assoc ? null : new StdClass(env.get());
ArrayMemory array = assoc ? new ArrayMemory() : stdClass.getProperties();
for (Map.Entry<String, JsonElement> el : jsonObject.entrySet()) {
String key = el.getKey();
if (!key.startsWith("\0"))
array.put(key, convert(el.getValue(), depth + 1).toImmutable());
}
return assoc ? array : new ObjectMemory(stdClass);
} else
return Memory.NULL;
}
use of php.runtime.memory.DoubleMemory in project jphp by jphp-compiler.
the class DateFunctions method gettimeofday.
public static Memory gettimeofday(boolean getAsFloat) {
long msec_time = System.currentTimeMillis();
if (getAsFloat) {
double now = msec_time / 1000.0;
return new DoubleMemory(now);
} else {
ArrayMemory result = new ArrayMemory();
TimeZone timeZone = TimeZone.getDefault();
long sec = msec_time / 1000;
long usec = (msec_time % 1000) * 1000;
long minuteswest = -timeZone.getOffset(msec_time) / MSEC_IN_MIN;
boolean is_dst = timeZone.inDaylightTime(new Date(msec_time));
result.refOfIndex("sec").assign(sec);
result.refOfIndex("usec").assign(usec);
result.refOfIndex("minuteswest").assign(minuteswest);
result.refOfIndex("dsttime").assign(is_dst ? 1 : 0);
return result.toConstant();
}
}
Aggregations