## /Prelude-v16.0.0/Integer/subtract

Copy path to clipboard

### Examples

`subtract +3 +5 ≡ +2`
`subtract +4 +4 ≡ +0`
`subtract +5 +3 ≡ -2`
`subtract -3 -5 ≡ -2`
`subtract -4 -4 ≡ +0`
`subtract -5 -3 ≡ +2`
`subtract -3 +5 ≡ +8`
`subtract +3 -5 ≡ -8`
`subtract +0 -3 ≡ -3`

### Source

`{-`subtract m n` computes `n - m`.-}let nonPositive =        ./nonPositive sha256:e00a852eed5b84ff60487097d8aadce53c9e5301f53ff4954044bd68949fac3b      ? ./nonPositivelet subtractNonNegative =        λ(xi : Integer)      → λ(yi : Integer)      → let xn = Integer/clamp xi        let yn = Integer/clamp yi        let dn = Natural/subtract xn yn        in        if Natural/isZero dn            then  Integer/negate (Natural/toInteger (Natural/subtract yn xn))            else  Natural/toInteger dnlet subtract    : Integer → Integer → Integer    =   λ(m : Integer)      → λ(n : Integer)      →       if nonPositive m        then        if nonPositive n              then  subtractNonNegative (Integer/negate n) (Integer/negate m)              else  Natural/toInteger                      (Integer/clamp (Integer/negate m) + Integer/clamp n)        else  if nonPositive n        then  Integer/negate                ( Natural/toInteger                    (Integer/clamp m + Integer/clamp (Integer/negate n))                )        else  subtractNonNegative m nlet example0 = assert : subtract +3 +5 ≡ +2let example1 = assert : subtract +4 +4 ≡ +0let example2 = assert : subtract +5 +3 ≡ -2let example3 = assert : subtract -3 -5 ≡ -2let example4 = assert : subtract -4 -4 ≡ +0let example5 = assert : subtract -5 -3 ≡ +2let example6 = assert : subtract -3 +5 ≡ +8let example7 = assert : subtract +3 -5 ≡ -8let example8 = assert : subtract +0 -3 ≡ -3in  subtract`