Why is UInt64 max equal -1 in Swift?
Using Swift, wether in terminal or playground, when I enter the following on a new line:
I get a result value of -1.
Is this a bug?
$ 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
4 Solutions Collect From Internet About “Why is UInt64 max equal -1 in Swift?”
I think it is a bug of terminal and playground.
But, the output of the println is correct(18446744073709551615) in both terminal and playground.
Looks like the same bug I’ve run into with any unsigned type.
echo “UInt8(255)” | xcrun swift
will also print -1
It’s because your processor is of 64 bit and UInt is 64 bit * 2.
The type Int can’t run this number, it’s out of range.
- When does NSURLSession run?
- CAShapeLayer circle not showing on iPhone 6, but its working on iPhone 5 with the same code
- Programmatically remove contact from adress book on specific time in swift
- SKMutablePayment property: applicationUsername
- when I use the line #include <OpenGL/gl.h> in my xcode project, where does it look for the gl.h file?
- UIGraphicsGetCurrentContext() short lifetime
- UINavigationController Interactive Pop Gesture Not Working?
- Xcode 7.2 bug: library not found for -lGoogleAnalyticsServices
- cell.contentView systemLayoutSizeFittingSize: does not work for dynamic height tableview
- invalid breakpoint with xcode 4.3
- How do I build the boost “Getting Started” examples using XCode?
- Is there a way to pass command line options to my iOS app from Xcode?
- Refresh only the custom header views in a UITableView?
- What's the best way to composite frame-based animated stickers over recorded video?
- Swift language NSClassFromString