jitsusama / uint128 Goto Github PK
View Code? Open in Web Editor NEWA Swift 128-bit Unsigned Integer Data Type conforming to the UnsignedInteger Protocol
License: Apache License 2.0
A Swift 128-bit Unsigned Integer Data Type conforming to the UnsignedInteger Protocol
License: Apache License 2.0
error message:
/Volumes/dev2/UInt128/Sources/UInt128.swift:542:1: Type 'UInt128' does not conform to protocol 'BinaryInteger'
/Volumes/dev2/UInt128/Sources/UInt128.swift:542:1: Type 'UInt128' does not conform to protocol 'BinaryInteger'
/Volumes/dev2/UInt128/Sources/UInt128.swift:542:1: Type 'UInt128' does not conform to protocol 'Numeric'
/Volumes/dev2/UInt128/Sources/UInt128.swift:347:21: Binary operator '&+' cannot be applied to operands of type 'UInt128' and 'Int'
/Volumes/dev2/UInt128/Sources/UInt128.swift:354:21: Binary operator '&-' cannot be applied to operands of type 'UInt128' and 'Int'
/Volumes/dev2/UInt128/Sources/UInt128.swift:368:25: Binary operator '&-' cannot be applied to two 'UInt128' operands
/Volumes/dev2/UInt128/Sources/UInt128.swift:370:21: Binary operator '&+' cannot be applied to two 'UInt128' operands
/Volumes/dev2/UInt128/Sources/UInt128.swift:673:69: Binary operator '&+' cannot be applied to two 'UInt128' operands
It would be handy to create a static variable to access the maximum 128 bit unsigned integer.
Similar to:
https://developer.apple.com/documentation/swift/uint64/1538705-max
Workaround is to use:
let maxValue = UInt128(upperBits: 0xFFFFFFFFFFFFFFFF, lowerBits: 0xFFFFFFFFFFFFFFFF)
// or
let maxValue: UInt128 = "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
Perhaps a few tests of the boundary conditions would give people more faith in the project?
Hey! Thanks for the tool.
Could you add a Podspec for your library?
let number = UInt128(4294967294)
//expected: number.significantBits == 31
//actually: number.significantBits == 32
quick fix:
--- significantBitCount += 1
+++ significantBitCount += UInt128(bitsToWalk & 1)
Please consider adding Carthage support (see https://github.com/Carthage/Carthage#supporting-carthage-for-your-framework).
any swift 3.0 version ?
I am wondering how everyone feels about doing a version bump on UInt128? If we were to do one, does everyone feel that it is ready for a 1.0.0 release? I'm also not up to date on Swift packaging. If I were to just push a tag for a new release, would that be enough for all of the cool package managers to find it, or should something else happen?
@gongzhang & @adamnemecek; I'm especially interested to hear your thoughts on this.
Because no build scheme for iOS platform, project depend UInt128 with Carthage will produce following error
Module file's minimum deployment target is ios11.0 v11.0
UInt128 -> String conversions are 50x slower than UInt64 native.
Here is an example test:
class PerformanceTests : XCTestCase {
func testStringPerformance64() {
let value: UInt64 = 17434549027881090559
measure {
// takes 1.3 seconds
for _ in 0..<100 {
_ = String(value, radix: 16)
}
}
}
func testStringPerformance128() {
let value = UInt128(upperBits: 17434549027881090559, lowerBits: 18373836492640810226)
measure {
// takes 78 seconds
for _ in 0..<100 {
_ = String(value, radix: 16)
}
}
}
}
One workaround could be to fix this only for radix 16. This strategy could be expanded to radix 2, 4, 8 & 32. Should we consider a PR like this?
internal func _valueToString(radix: Int = 10, uppercase: Bool = true) -> String {
precondition((2...36) ~= radix, "radix must be within the range of 2-36.")
// Simple case.
if self == 0 {
return "0"
}
// Will store the final string result.
var result = String()
// workaround for fast HEX output
if radix == 16 {
let lowerString = String(value.lowerBits, radix: radix)
if value.upperBits == 0 {
result = lowerString
}
else {
result = String(value.upperBits, radix: radix)
result.append(String(repeating: "0", count: 16 - lowerString.count))
result += lowerString
}
return result
}
// ... rest of the existing solution here
This improves the speed by a factor of 50, but for radix 16 only.
I've added this line in dependencies
.package(url: "https://github.com/Jitsusama/UInt128.git", from: "0.8.0")
but I'm getting this error when resolving a package:
error: the package dependency graph could not be resolved; unable to find any available tag for the following requirements: https://github.com/Jitsusama/UInt128.git @ 0.8.0..<1.0.0
I checked tags and both are there "0.8.0" and "v0.8.0", a bit strange ... what could be the issue?
The following code produced a cast error
let val: UInt128 = UInt128.max
String.init(format: "0x%0X", val as! CVarArg )
Do you have any advice on how to solve this problem?
Hey Joel,
If I wanted to implement UInt256, would I essentially just duplicate your work with a project with UInt128 in it and double all the 64 values to 128?
This issue is a reminder that I need to bump the version number up to 0.9.0 since we've added Codable
support to the library.
from this PR, ArithmeticOverflow was remove so the swift4 branch do not compile
apple/swift#11203
I use swift3.2 branch,but i can't find fromUnparsedString
this Instance method.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.