Arithmetic/Integer: Difference between revisions

no edit summary
m (→‎{{header|GDScript}}: Rounding/remainder annotations)
No edit summary
Line 1,802:
Modulo: -1
Exponent: -0.0029154518950437317
</pre>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^|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)
</syntaxhighlight>
{{out}}
<pre>
emal.exe Org\RosettaCode\AritmeticInteger.emal
first number: 19
second number: 7
sum: 26
difference: 12
product: 133
integer quotient: 2
remainder: 5
exponentiation: 893871739
logarithm: 2
divmod: [2,5]
</pre>
 
214

edits