Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Arithmetic-Integer/EMal/arithmetic-integer.emal
Normal file
30
Task/Arithmetic-Integer/EMal/arithmetic-integer.emal
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
^|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 = Pair by int dividend, int divisor
|
||||
Pair result = int%int().named("quotient", "remainder")
|
||||
result.quotient = dividend / divisor
|
||||
result.remainder = dividend % divisor
|
||||
return result
|
||||
end
|
||||
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("exponentiation: " + (a ** b))
|
||||
writeLine("logarithm: " + (a // b))
|
||||
writeLine("divmod: " + divmod(a, b))
|
||||
return 0
|
||||
end
|
||||
exit main(Runtime.args)
|
||||
Loading…
Add table
Add a link
Reference in a new issue