# BigDecimal functionalities or modulus support for NSDecimalNumber

**URL:** <https://forums.swift.org/t/bigdecimal-functionalities-or-modulus-support-for-nsdecimalnumber/3145>\
**Category:** Discussion\
**Created:** [June 25, 2016, 7:06pm UTC](https://forums.swift.org/t/bigdecimal-functionalities-or-modulus-support-for-nsdecimalnumber/3145 "2016-06-25T19:06:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Leganza](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Andrea\_Leganza](https://forums.swift.org/u/Andrea_Leganza)\
**Post date:** [June 25, 2016, 7:06pm UTC](https://forums.swift.org/t/bigdecimal-functionalities-or-modulus-support-for-nsdecimalnumber/3145/1 "2016-06-25T19:06:58Z")

</div>

Hello all,

i was working with huge int numbers (28 digits) due to the developing of an algorithm to check the validity of IBAN bank codes (source: [https://en.wikipedia.org/wiki/International\_Bank\_Account\_Number\](https://en.wikipedia.org/wiki/International_Bank_Account_Number%5C))

The algorithm requests to check the modulus of the 28 digits number with value 97, the only type which was useful due to the size which can contain was NSDecimalNumber ([Apple Developer Documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDecimalNumber_Class/%5C)) which doesn’t support modulus

I had to use and external library like this one: [GitHub - mkrd/Swift-BigInt: A lightweight, Multiple Precision Arithmetic Library for Swift!](https://github.com/mkrd/Swift-Big-Integer) which supports int and double, maybe adding the modulus operation to NSDecimalNumber will be useful for some users or creating a framework to manage huge int or double.

if something already exists sorry for the trouble.

best regards.  
eng. Andrea Leganza

> **···**
>
> —————————————————  
> Docente di Fondamenti di programmazione c/o Istituto Quasar - Roma  
> Docente di Progettazione di Applicazioni per Dispositivi Mobili c/o Istituto Quasar - Roma  
> Docente di Unity3D c/o Vigamus Academy - Roma  
> Docente di Programmazione Web c/o ENAIP - Roma  
> Redattore magazine Io Programmo - ed. Master  
> Adobe Flex & Air certified  
> Sun Java 1.6 Certified  
> EUCIP Core Certified

---

<div class="post-metadata">

**Author:** ![Charlie\_Monroe1](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@Charlie\_Monroe1](https://forums.swift.org/u/Charlie_Monroe1)\
**Post date:** [June 27, 2016, 4:50am UTC](https://forums.swift.org/t/bigdecimal-functionalities-or-modulus-support-for-nsdecimalnumber/3145/2 "2016-06-27T04:50:56Z")

</div>

It shouldn't be hard to add your own modulo implementation:

mod = code - (floor(code / 97) \* 97)

given all operations are on NSDecimalNumber (or Decimal in Swift 3.0)...

> **···**
>
> > On Jun 25, 2016, at 9:06 PM, Andrea Leganza via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > Hello all,
> > 
> > i was working with huge int numbers (28 digits) due to the developing of an algorithm to check the validity of IBAN bank codes (source: [https://en.wikipedia.org/wiki/International\_Bank\_Account\_Number\](https://en.wikipedia.org/wiki/International_Bank_Account_Number%5C))
> > 
> > The algorithm requests to check the modulus of the 28 digits number with value 97, the only type which was useful due to the size which can contain was NSDecimalNumber ([NSDecimalNumber | Apple Developer Documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDecimalNumber_Class/%5C)) which doesn’t support modulus
> > 
> > I had to use and external library like this one: [GitHub - mkrd/Swift-BigInt: A lightweight, Arbitrary Precision Arithmetic Library for Swift!](https://github.com/mkrd/Swift-Big-Integer) which supports int and double, maybe adding the modulus operation to NSDecimalNumber will be useful for some users or creating a framework to manage huge int or double.
> > 
> > if something already exists sorry for the trouble.
> > 
> > best regards.  
> > eng. Andrea Leganza  
> > —————————————————  
> > Docente di Fondamenti di programmazione c/o Istituto Quasar - Roma  
> > Docente di Progettazione di Applicazioni per Dispositivi Mobili c/o Istituto Quasar - Roma  
> > Docente di Unity3D c/o Vigamus Academy - Roma  
> > Docente di Programmazione Web c/o ENAIP - Roma  
> > Redattore magazine Io Programmo - ed. Master  
> > Adobe Flex & Air certified  
> > Sun Java 1.6 Certified  
> > EUCIP Core Certified
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
