28 lines
1.0 KiB
Plaintext
28 lines
1.0 KiB
Plaintext
^|EMal has no divmod operator or built-in function,
|
|
|its interface can be easily emulated as shown below.
|
|
|The performace is worse than using / and % operators.
|
|
|^
|
|
fun divmod ← <int dividend, int divisor|int%int(dividend / divisor ⇒
|
|
dividend % divisor).named("quotient", "remainder")
|
|
fun main ← int by List args
|
|
int a, b
|
|
if args.length æ 2
|
|
a ← int!args[0]
|
|
b ← int!args[1]
|
|
else
|
|
a ← ask(int, "first number: ")
|
|
b ← ask(int, "second number: ")
|
|
end
|
|
writeLine("sum: " + (a + b))
|
|
writeLine("difference: " + (a - b))
|
|
writeLine("product: " + (a * b))
|
|
writeLine("integer quotient: " + (a / b)) # truncates towards 0
|
|
writeLine("remainder: " + (a % b)) # matches sign of first operand
|
|
writeLine("divmod: " + divmod(a, b))
|
|
writeLine("exponent: " + (a ** b)) # a raised to the power of b
|
|
writeLine("root: " + (a // b)) # a √ b
|
|
writeLine("logarithm: " + (a %% b)) # log a (b)
|
|
return 0
|
|
end
|
|
exit main(Runtime.args)
|