Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is UInt64 max equal -1 in Swift?

Using Swift, wether in terminal or playground, when I enter the following on a new line:

UInt64.max

I get a result value of -1.

Is this a bug?


Edit: Examples

$ 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
like image 832
Khaled Barazi Avatar asked Oct 21 '22 06:10

Khaled Barazi


1 Answers

I think it is a bug of terminal and playground.

But, the output of the println is correct(18446744073709551615) in both terminal and playground.

like image 114
mono Avatar answered Dec 20 '22 02:12

mono