gpt4 book ai didi

java - Python 解析 Java Double.toHexString(double) 的输出

转载 作者:行者123 更新时间:2023-12-02 06:12:29 26 4
gpt4 key购买 nike

是否可以在 Python 中解析从 Java Double.toHexString 方法编写的字符串?

http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toHexString(double)

输出如下所示:“0x1.16d6b97e718ffp8”...不确定这是否是标准化格式。

我期望类似的东西

value=float('0x1.16d6b97e718ffp8')

最佳答案

那就是float.fromhex :

>>> float.fromhex('0x1.16d6b97e718ffp8')
278.8387679126026

来自文档:

This syntax is similar to the syntax specified in section 6.4.4.2 of the C99 standard, and also to the syntax used in Java 1.5 onwards. In particular, the output of float.hex() is usable as a hexadecimal floating-point literal in C or Java code, and hexadecimal strings produced by C’s %a format character or Java’s Double.toHexString are accepted by float.fromhex().

关于java - Python 解析 Java Double.toHexString(double) 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21768587/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com