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

后端 未结 4 514
鱼传尺愫
鱼传尺愫 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:57

    You can implement your own UInt128 type. Or use NSDecimalNumber

    To implement UInt128

    struct UInt128 {
        var low : UInt64 = 0;
        var high : UInt64 = 0;
    }
    

    and you can implement operators

    infix func + (l: UInt128, r: UInt128) -> UInt128 {
        // do your work... care with overflow 
    }
    

提交回复
热议问题