Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Modular-arithmetic/Tcl/modular-arithmetic-2.tcl
Normal file
19
Task/Modular-arithmetic/Tcl/modular-arithmetic-2.tcl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# The semantic evaluation engine; this is the part that knows mod arithmetic
|
||||
oo::class create ModEval {
|
||||
variable mod
|
||||
constructor {modulo} {set mod $modulo}
|
||||
method value {literal} {return [expr {$literal}]}
|
||||
method variable {name} {return [expr {[set ::$name]}]}
|
||||
method + {a b} {return [expr {($a + $b) % $mod}]}
|
||||
method - {a b} {return [expr {($a - $b) % $mod}]}
|
||||
method * {a b} {return [expr {($a * $b) % $mod}]}
|
||||
method / {a b} {return [expr {($a / $b) % $mod}]}
|
||||
method ** {a b} {
|
||||
# Tcl supports bignums natively, so we use the naive version
|
||||
return [expr {($a ** $b) % $mod}]
|
||||
}
|
||||
export + - * / **
|
||||
}
|
||||
|
||||
# Put all the pieces together
|
||||
set comp [CompileAST new [ModEval create mod13 13]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue