php.runtime.Memory.toDouble()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中php.runtime.Memory.toDouble()方法的一些代码示例,展示了Memory.toDouble()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Memory.toDouble()方法的具体详情如下:
包路径:php.runtime.Memory
类名称:Memory
方法名:toDouble

Memory.toDouble介绍

暂无

代码示例

代码示例来源:origin: jphp-group/jphp

public Map<String, Double> toDoubleMap() {
  Map<String, Double> r = new LinkedHashMap<String, Double>();
  ForeachIterator iterator = foreachIterator(false, false);
  while (iterator.next()) {
    r.put(iterator.getKey().toString(), iterator.getValue().toDouble());
  }
  return r;
}

代码示例来源:origin: jphp-group/jphp

public static Memory range(Environment env, TraceInfo trace, Memory low, Memory high, Memory step) {
  if (low.getRealType() == Memory.Type.DOUBLE || high.getRealType() == Memory.Type.DOUBLE || step.getRealType() == Memory.Type.DOUBLE) {
    return _range_double(env, trace, low.toDouble(), high.toDouble(), step.toDouble());
  } else {
    return _range_long(env, trace, low.toLong(), high.toLong(), step.toLong());
  }
}

代码示例来源:origin: jphp-group/jphp

public Memory pow(long value) {
  Memory real = toNumeric();
  if (real instanceof LongMemory) {
    double result = Math.pow(real.toLong(), value);
    if (result > Long.MAX_VALUE) {
      return new DoubleMemory(result);
    }
    return new LongMemory((long) result);
  }
  return new DoubleMemory(Math.pow(real.toDouble(), value));
}
public Memory pow(double value) { return new DoubleMemory(Math.pow(toDouble(), value)); }

代码示例来源:origin: jphp-group/jphp

@Override
public boolean smaller(Memory memory) {
  switch (memory.type){
    case DOUBLE: return value < ((DoubleMemory)memory).value;
    case INT: return value < ((LongMemory)memory).value;
    case REFERENCE: return smaller(memory.toValue());
    default:
      return smaller(memory.toDouble());
  }
}

代码示例来源:origin: jphp-group/jphp

@Immutable
public static double sin(Memory memory){
  switch (memory.type){
    case DOUBLE: return Math.sin(memory.toDouble());
    case STRING: return sin(memory.toNumeric());
    default:
      return _sin(memory.toLong());
  }
}

代码示例来源:origin: jphp-group/jphp

@Immutable
public static double cos(Memory memory){
  switch (memory.type){
    case DOUBLE: return Math.cos(memory.toDouble());
    case STRING: return cos(memory.toNumeric());
    default:
      return _cos(memory.toLong());
  }
}

代码示例来源:origin: jphp-group/jphp

@Override
public Number convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
  switch (arg.getRealType()) {
    case DOUBLE: return arg.toDouble();
    case INT: return arg.toInteger();
    default:
      return convert(env, trace, arg.toNumeric());
  }
}

代码示例来源:origin: jphp-group/jphp

public static Memory mul(long o1, Memory value) {
  switch (value.type){
    case INT: return LongMemory.valueOf(o1 * value.toLong());
    case DOUBLE: return DoubleMemory.valueOf(o1 * value.toDouble());
  }
  return mul(o1, value.toNumeric());
}
public static Memory mul(double o1, Memory value) { return DoubleMemory.valueOf(o1 * value.toDouble()); }

代码示例来源:origin: jphp-group/jphp

@Test
public void testCallNativeFunc(){
  Memory memory = runDynamic("$i = 1; return cos($i);", false);
  Assert.assertTrue(memory.toDouble() > 0.54);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testMul(){
  DoubleMemory memory = new DoubleMemory(10);
  Assert.assertEquals(20, memory.mul(2).toDouble(), 0.00001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.mul(2).type);
  Assert.assertEquals(10, memory.mul(true).toDouble(), 0.00001);
  Assert.assertEquals(0, memory.mul(false).toDouble(), 0.00001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.mul(false).type);
  Assert.assertEquals(20, memory.mul(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.mul(2.0).type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testPlus(){
  DoubleMemory memory = new DoubleMemory(10);
  Assert.assertEquals(12, memory.plus(2).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.plus(2).type);
  Assert.assertEquals(11, memory.plus(true).toDouble(), 0.00001);
  Assert.assertEquals(10, memory.plus(false).toDouble(), 0.00001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.plus(false).type);
  Assert.assertEquals(12, memory.plus(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.plus(2.0).type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testPow(){
  DoubleMemory memory = new DoubleMemory(10);
  Assert.assertEquals(100, memory.pow(2).toDouble(), 0.00001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.pow(2).type);
  Assert.assertEquals(10, memory.pow(true).toDouble(), 0.00001);
  Assert.assertEquals(1, memory.pow(false).toDouble(), 0.00001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.pow(false).type);
  Assert.assertEquals(100, memory.pow(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.pow(2.0).type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testDiv(){
  DoubleMemory memory = new DoubleMemory(10);
  Assert.assertEquals(5, memory.div(2).toDouble(), 0.00001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.div(2).type);
  Assert.assertEquals(10, memory.div(true).toDouble(), 0.000001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.div(true).type);
  Assert.assertEquals(5, memory.div(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.div(2.0).type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testMathComplex(){
  Memory memory = runDynamic("3 + $x * 4");
  Assert.assertEquals(3, memory.toLong());
  memory = runDynamic("(3 + $x * 4) / 2");
  Assert.assertEquals(1.5, memory.toDouble(), 0.000001);
  memory = runDynamic("$y = 2; return (7 + $x * 4) / $y;", false);
  Assert.assertEquals(3.5, memory.toDouble(), 0.000001);
  memory = runDynamic("$y = 2; return (8 + $x * 4) / $y * 2;", false);
  Assert.assertEquals(8, memory.toLong());
  Assert.assertEquals(Memory.Type.INT, memory.type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testTyped(){
  Assert.assertTrue(Memory.TRUE.toBoolean());
  Assert.assertEquals("1", Memory.TRUE.toString());
  Assert.assertEquals(1.0, Memory.TRUE.toDouble(), 0.00001);
  Assert.assertEquals(Memory.TRUE, Memory.TRUE.toImmutable());
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testInc(){
  StringMemory memory = new StringMemory("3");
  Assert.assertEquals(4, memory.inc().toLong());
  Assert.assertEquals(Memory.Type.INT, memory.inc().type);
  memory = new StringMemory("2.3");
  Assert.assertEquals(3.3, memory.inc().toDouble(), 0.000001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.inc().type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testScalarJsonDecode() {
  assertEquals(Memory.TRUE, JsonFunctions.json_decode(env, "true"));
  assertEquals(Memory.FALSE, JsonFunctions.json_decode(env, "false"));
  assertEquals(Memory.NULL, JsonFunctions.json_decode(env, "null"));
  assertEquals(LongMemory.valueOf(5), JsonFunctions.json_decode(env, "5"));
  assertEquals(3.1, JsonFunctions.json_decode(env, "3.1").toDouble(), 0.00000001);
  assertEquals("foobar", JsonFunctions.json_decode(env, "\"foobar\"").toString());
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testMinus(){
  LongMemory memory = new LongMemory(10);
  Assert.assertEquals(8, memory.minus(2).toLong());
  Assert.assertEquals(Memory.Type.INT, memory.minus(2).type);
  Assert.assertEquals(9, memory.minus(true).toLong());
  Assert.assertEquals(10, memory.minus(false).toLong());
  Assert.assertEquals(Memory.Type.INT, memory.minus(false).type);
  Assert.assertEquals(8.0, memory.minus(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.minus(2.0).type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testPlus(){
  LongMemory memory = new LongMemory(10);
  Assert.assertEquals(12, memory.plus(2).toLong());
  Assert.assertEquals(Memory.Type.INT, memory.plus(2).type);
  Assert.assertEquals(11, memory.plus(true).toLong());
  Assert.assertEquals(10, memory.plus(false).toLong());
  Assert.assertEquals(Memory.Type.INT, memory.plus(false).type);
  Assert.assertEquals(12, memory.plus(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.plus(2.0).type);
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testMinus(){
  LongMemory memory = new LongMemory(10);
  Assert.assertEquals(8, memory.minus(2).toLong());
  Assert.assertEquals(Memory.Type.INT, memory.minus(2).type);
  Assert.assertEquals(9, memory.minus(true).toLong());
  Assert.assertEquals(10, memory.minus(false).toLong());
  Assert.assertEquals(Memory.Type.INT, memory.minus(false).type);
  Assert.assertEquals(8.0, memory.minus(2.0).toDouble(), 0.0001);
  Assert.assertEquals(Memory.Type.DOUBLE, memory.minus(2.0).type);
}

相关文章