Sha256: 5e5e2b98ba5a18d0ca420f9dbfc00a0c78acecffc5f9b4792673ced76b3fbd83
Contents?: true
Size: 1.37 KB
Versions: 10
Compression:
Stored size: 1.37 KB
Contents
// version 1.1 fun main(args: Array<String>) { val r = Regex("""-?\d+[ ]+-?\d+""") while(true) { print("Enter two integers separated by space(s) or q to quit: ") val input: String = readLine()!!.trim() if (input == "q" || input == "Q") break if (!input.matches(r)) { println("Invalid input, try again") continue } val index = input.lastIndexOf(' ') val a = input.substring(0, index).trimEnd().toLong() val b = input.substring(index + 1).toLong() println("$a + $b = ${a + b}") println("$a - $b = ${a - b}") println("$a * $b = ${a * b}") if (b != 0L) { println("$a / $b = ${a / b}") // rounds towards zero println("$a % $b = ${a % b}") // if non-zero, matches sign of first operand } else { println("$a / $b = undefined") println("$a % $b = undefined") } val d = Math.pow(a.toDouble(), b.toDouble()) print("$a ^ $b = ") if (d % 1.0 == 0.0) { if (d >= Long.MIN_VALUE.toDouble() && d <= Long.MAX_VALUE.toDouble()) println("${d.toLong()}") else println("out of range") } else if (!d.isFinite()) println("not finite") else println("not integral") println() } }
Version data entries
10 entries across 7 versions & 1 rubygems