Swift double float Int 有效位数 取值
Floating-point types can represent a much wider range of values than integer types, and can store numbers that are much larger or smaller than can be stored in an Int. Swift provides two signed floating-point number types:
Double represents a 64-bit floating-point number.
Float represents a 32-bit floating-point number.
Int
In most cases, you don’t need to pick a specific size of integer to use in your code. Swift provides an additional integer type, Int, which has the same size as the current platform’s native word size:
On a 32-bit platform, Int is the same size as Int32.
On a 64-bit platform, Int is the same size as Int64.
int 整型
float 单精度浮点
double 双精度浮点
int 32/64 系统 32/64 取值范围: 有效数位 7/15
float 32 取值范围是-126-127 有效数位 7
double 64 取值范围是-1022 - 1023 有效数位15
在32位浮点数中,符号位占1位,尾数占23位,阶数占8位。在正常情况下,阶数不包括全零和全一的情况,偏置常数是127,因此它的取值范围是-126-127。尾数值等于1+尾数23位表示的小数。
在64位浮点数中,符号位占1位,尾数占52位,阶数占11位。在正常情况下,阶数不包括全零和全一的情况,偏置常数是1023,因此它的取值范围是-1022 - 1023,尾数值等于1+尾数52位表示的小数。