在Swift编程语言官方文档中,
Double represents a 64-bit floating-point number.
Float represents a 32-bit floating-point number.
链接:https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID321
然后,为什么会有Float64?它们之间有什么区别?还是一样?
答案 0 :(得分:1)
转到Float64
的定义
/// A 64-bit floating point type.
public typealias Float64 = Double
/// A 32-bit floating point type.
public typealias Float32 = Float
答案 1 :(得分:1)
通过点击命令 + shift + o 并搜索Float64
可以找到标题,例如:
/// A 64-bit floating point type.
public typealias Float64 = Double
/// A 32-bit floating point type.
public typealias Float32 = Float
和
Base floating point types
Float32 32 bit IEEE float: 1 sign bit, 8 exponent bits, 23 fraction bits
Float64 64 bit IEEE float: 1 sign bit, 11 exponent bits, 52 fraction bits
Float80 80 bit MacOS float: 1 sign bit, 15 exponent bits, 1 integer bit, 63 fraction bits
Float96 96 bit 68881 float: 1 sign bit, 15 exponent bits, 16 pad bits, 1 integer bit, 63 fraction bits
Note: These are fixed size floating point types, useful when writing a floating
point value to disk. If your compiler does not support a particular size
float, a struct is used instead.
Use of of the NCEG types (e.g. double_t) or an ANSI C type (e.g. double) if
you want a floating point representation that is natural for any given
compiler, but might be a different size on different compilers.
通常,除非您要编写依赖于二进制表示形式的代码,否则应使用标准的Float
v Double
名称。但是,如果您在编写需要二进制兼容性的内容(例如,编写/解析二进制Data
与其他平台进行交换),则可以使用名称中带有位数的数据类型,例如Float32
与Float64
对比Float80
。