Sha256: 9cc8f4dde1454f0625695f2fa6e2a70b1e77c2bb5a971b747840df594c8e79f7

Contents?: true

Size: 701 Bytes

Versions: 10

Compression:

Stored size: 701 Bytes

Contents

'''Solution:'''
def arithmetic = { a, b ->
    println """
       a + b =        ${a} + ${b} = ${a + b}
       a - b =        ${a} - ${b} = ${a - b}
       a * b =        ${a} * ${b} = ${a * b}
       a / b =        ${a} / ${b} = ${a / b}   !!! Converts to floating point!
(int)(a / b) = (int)(${a} / ${b}) = ${(int)(a / b)}              !!! Truncates downward after the fact
 a.intdiv(b) =  ${a}.intdiv(${b}) = ${a.intdiv(b)}              !!! Behaves as if truncating downward, actual implementation varies
       a % b =        ${a} % ${b} = ${a % b}

Exponentiation is also a base arithmetic operation in Groovy, so:
      a ** b =       ${a} ** ${b} = ${a ** b}
"""
}

'''Test:'''
arithmetic(5,3)

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/groovy.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/groovy.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/groovy.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/groovy.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/groovy.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/groovy.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/groovy.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/groovy.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/groovy.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/groovy.txt