floating-Point literals
…
Hexadecimal floating-point literals consist of a 0x prefix,followed
by an optional hexadecimal fraction,followed by a hexadecimal
exponent. The hexadecimal fraction consists of a decimal point
followed by a sequence of hexadecimal digits. The exponent consists of
an upper- or lowercase p prefix followed by a sequence of decimal
digits that indicates what power of 2 the value preceding the p is
multiplIEd by. For example,0xFp2 represents 15 × 22,which evaluates
to 60. Similarly,0xFp-2 represents 15 × 2-2,which evaluates to 3.75.
在你的情况下
0xC.3p0 = (12 + 3/16) * 2^0 = 12.1875
另一个例子:
0xAB.CDp4 = (10*16 + 11 + 12/16 + 13/16^2) * 2^4 = 2748.8125
此格式与%a printf-format非常相似(例如,请参阅
http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html).
它可以用于直接在其中指定浮点数
二进制IEEE 754表示,见Why does Swift use base 2 for the exponent of hexadecimal floating point values?欲获得更多信息.
以上是内存溢出为你收集整理的Swift中的浮点十六进制表示法全部内容,希望文章能够帮你解决Swift中的浮点十六进制表示法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)