为什么 UInt64 max 在 Swift 中等于 -1? [英] Why is UInt64 max equal -1 in Swift?
本文介绍了为什么 UInt64 max 在 Swift 中等于 -1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在终端或操场中使用 Swift,当我在新行中输入以下内容时:
Using Swift, wether in terminal or playground, when I enter the following on a new line:
UInt64.max
我得到的结果值为 -1.
I get a result value of -1.
这是一个错误吗?
示例
$ xcrun swift
Welcome to Swift! Type :help for assistance.
1> UInt64.max / 2
$R1: UInt64 = 9223372036854775807
2> UInt64.max / 2 + 1
$R2: UInt64 = -9223372036854775808
3> UInt64.max
$R3: UInt64 = -1
4> println(UInt64.max / 2)
9223372036854775807
5> println(UInt64.max / 2 + 1)
9223372036854775808
6> println(UInt64.max)
18446744073709551615
推荐答案
我觉得是终端和playground的bug.
I think it is a bug of terminal and playground.
但是,println 的输出在终端和操场上都是正确的(18446744073709551615).
But, the output of the println is correct(18446744073709551615) in both terminal and playground.
这篇关于为什么 UInt64 max 在 Swift 中等于 -1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文