java.lang.Float.toHexString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(177)

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

Float.toHexString介绍

[英]Converts the specified float into its hexadecimal string representation.
[中]将指定的浮点转换为其十六进制字符串表示形式。

代码示例

代码示例来源:origin: google/guava

@GwtIncompatible // Floats.tryParse
public void testTryParseOfToHexStringIsOriginal() {
 for (float f : NUMBERS) {
  checkTryParse(f, Float.toHexString(f));
 }
}

代码示例来源:origin: robovm/robovm

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: konsoletyper/teavm

@Override
public void visit(WasmFloat32Constant expression) {
  open().append("f32.const " + Float.toHexString(expression.getValue())).close();
}

代码示例来源:origin: konsoletyper/teavm

@Override
public void visit(WasmFloat32Constant expression) {
  if (Float.isInfinite(expression.getValue())) {
    value = CExpression.relocatable(expression.getValue() < 0 ? "-INFINITY" : "INFINITY");
  } else if (Float.isNaN(expression.getValue())) {
    value = CExpression.relocatable("NAN");
  } else {
    value = CExpression.relocatable(Float.toHexString(expression.getValue()) + "F");
  }
}

代码示例来源:origin: stackoverflow.com

class Test {
  public static void main(String[] args) {
    System.out.println("3.2F is: "+Float.toHexString(3.2F));
    System.out.println("3.2  is: "+Double.toHexString(3.2));
    System.out.println("6.5F is: "+Float.toHexString(6.5F));
    System.out.println("6.5  is: "+Double.toHexString(6.5));
  }
}
$ java Test
3.2F is: 0x1.99999ap1
3.2  is: 0x1.999999999999ap1
6.5F is: 0x1.ap2
6.5  is: 0x1.ap2

代码示例来源:origin: nuls-io/nuls

/**
 * override
 *
 * @see Float#toHexString(float)
 */
private static Result toHexString(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
  float f = (float) methodArgs.invokeArgs[0];
  String s = Float.toHexString(f);
  ObjectRef ref = frame.heap.newString(s);
  Result result = NativeMethod.result(methodCode, ref, frame);
  return result;
}

代码示例来源:origin: org.teavm/teavm-core

@Override
public void visit(WasmFloat32Constant expression) {
  value = CExpression.relocatable(Float.toHexString(expression.getValue()) + "F");
}

代码示例来源:origin: MobiVM/robovm

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: org.teavm/teavm-core

@Override
public void visit(WasmFloat32Constant expression) {
  open().append("f32.const " + Float.toHexString(expression.getValue())).close();
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: ibinti/bugvm

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: com.jtransc/jtransc-rt

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: com.gluonhq/robovm-rt

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: com.bugvm/bugvm-rt

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: FlexoVM/flexovm

private void transformA(StringBuilder result) {
  if (arg instanceof Float) {
    result.append(Float.toHexString(((Float) arg).floatValue()));
  } else if (arg instanceof Double) {
    result.append(Double.toHexString(((Double) arg).doubleValue()));
  } else {
    throw badArgumentType();
  }
  if (!formatToken.isPrecisionSet()) {
    return;
  }
  int precision = formatToken.getPrecision();
  if (precision == 0) {
    precision = 1;
  }
  int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
  int indexOfP = result.indexOf("p");
  int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
  if (fractionalLength == precision) {
    return;
  }
  if (fractionalLength < precision) {
    char[] zeros = new char[precision - fractionalLength];
    Arrays.fill(zeros, '0'); // %a shouldn't be localized.
    result.insert(indexOfP, zeros);
    return;
  }
  result.delete(indexOfFirstFractionalDigit + precision, indexOfP);
}

代码示例来源:origin: itesla/ipst

if (actionParameters.getValue(name) instanceof Float) {
  type = "FLOAT";
  value = Float.toHexString((Float) actionParameters.getValue(name));

代码示例来源:origin: com.google.guava/guava-tests

@GwtIncompatible // Floats.tryParse
public void testTryParseOfToHexStringIsOriginal() {
 for (float f : NUMBERS) {
  checkTryParse(f, Float.toHexString(f));
 }
}

相关文章