Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -0,0 +1,17 @@
( enter
= put$"Enter two integer numbers, separated by space:"
& get':(~/#?k_~/#?m|quit:?k)
| out
$ "You must enter two integer numbers! Enter \"quit\" if you don't know how to do that."
& !enter
)
& !enter
& !k:~quit
& out$("You entered" !k and !m ". Now look:")
& out$("Sum:" !k+!m)
& out$("Difference:" !k+-1*!m)
& out$("Product:" !k*!m)
& out$("Integer division:" div$(!k.!m))
& out$("Remainder:" mod$(!k.!m))
& out$("Exponentiation:" !k^!m)
& done;

View file

@ -0,0 +1,11 @@
Function( a, b )
? "a+b", a + b
? "a-b", a - b
? "a*b", a * b
// The quotient isn't integer, so we use the Int() function, which truncates it downward.
? "a/b", Int( a / b )
// Remainder:
? "a%b", a % b
// Exponentiation is also a base arithmetic operation
? "a**b", a ** b
Return Nil

View file

@ -1,6 +1,5 @@
#define system.
#define extensions'io.
#define extensions'math.
#define extensions.
// --- Program ---
@ -13,5 +12,5 @@
consoleEx << a << " - " << b << " = " << a - b << "%n".
consoleEx << a << " * " << b << " = " << a * b << "%n".
consoleEx << a << " / " << b << " = " << a / b << "%n". // truncates towards 0
consoleEx << a << " %% " << b << " = " << (modulus:a:b) << "%n". // matches sign of first operand
consoleEx << a << " %% " << b << " = " << (a~mathOp mod:b) << "%n". // matches sign of first operand
].

View file

@ -0,0 +1,22 @@
import parseopt,strutils
var
opt: TOptParser = initOptParser()
str = opt.cmdLineRest.split
a: int = 0
b: int = 0
try:
a = parseInt(str[0])
b = parseInt(str[1])
except EinvalidValue:
quit("Invalid params. Two integers are expected.")
echo ("a : " & $a)
echo ("b : " & $b)
echo ("a + b : " & $(a+b))
echo ("a - b : " & $(a-b))
echo ("a * b : " & $(a*b))
echo ("a div b: " & $(a div b))
echo ("a mod b: " & $(a mod b))

View file

@ -0,0 +1,17 @@
'Arithmetic - Integer
Sub RosettaArithmeticInt()
Dim opr As Variant, a As Integer, b As Integer
On Error Resume Next
a = CInt(InputBox("Enter first integer", "XLSM | Arithmetic"))
b = CInt(InputBox("Enter second integer", "XLSM | Arithmetic"))
Debug.Print "a ="; a, "b="; b, vbCr
For Each opr In Split("+ - * / \ mod ^", " ")
Select Case opr
Case "mod": Debug.Print "a mod b", a; "mod"; b, a Mod b
Case "\": Debug.Print "a \ b", a; "\"; b, a \ b
Case Else: Debug.Print "a "; opr; " b", a; opr; b, Evaluate(a & opr & b)
End Select
Next opr
End Sub