Is there a number type with bigger capacity than u_long/UInt64 in Swift?

后端 未结 4 480
鱼传尺愫
鱼传尺愫 2021-01-19 06:21

Is there a type with bigger capacity than u_long or UInt64 in Swift?

I have a function that takes very big integers to identify a credit card numbe

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 06:36

    Another approach would be to work with strings, and define the mathematical operators to operate on strings also:

    func +(lhs: String, rhs: Int8) -> String
    func +(lhs: String, rhs: Int16) -> String
    func +(lhs: String, rhs: Int32) -> String
    func +(lhs: String, rhs: Int64) -> String
    func +(lhs: String, rhs: String) -> String
    // ... other operators
    

    This has the advantage of theoretically allowing and unlimited number of digits, but has the disadvantage of the fact that the strings might not always represent numbers.

提交回复
热议问题