ios - swift定义十六进制数据包含小数部分的时候指数部分不可缺少吗?
黄舟
黄舟 2017-04-17 13:11:29
0
1
607
let hexadecimalDouble = 0xC.3p0

这里不能定义成

let hexadecimalDouble = 0xC.3

但是如果没有小数部分,如

let hexadecimalDouble = 0xC

是可以的。

这是编译器的疏漏还是语言的特殊设定,如果是后者的话为什么这样?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
左手右手慢动作
// All of these floating-point literals have a decimal value of 12.1875:
let decimalDouble = 12.1875
let exponentDouble = 1.21875e1
let hexadecimalDouble = 0xC.3p0

/*
* explain why hexadecimalDouble = 0xC.3p0 equal 12.1875
* 解释为什么 hexadecimalDouble = 0xC.3p0 等于 12.1875
* 将其转换为16进制

         0x         C .    3  p0  = 0xCp0 + 0x3p-4 = 12 + 3*(1/16)
    0xC.3 = 0000 0110 . 0011

// example:
var hexadecimalDoubleTest = 0x0.33p0   
// 0x0.33p0 = 0x3p-4 + 0x3p-8 = 3*(1/16)+3*(1/256) = 0.19921875
*/
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template