separated into modules, added parser and lexer for miniImp
This commit is contained in:
5
lib/utility/dune
Normal file
5
lib/utility/dune
Normal file
@ -0,0 +1,5 @@
|
||||
(library
|
||||
(name utility)
|
||||
(public_name utility))
|
||||
|
||||
(include_subdirs qualified)
|
||||
13
lib/utility/utility.ml
Normal file
13
lib/utility/utility.ml
Normal file
@ -0,0 +1,13 @@
|
||||
let rec pow a = function
|
||||
| 0 -> 1
|
||||
| 1 -> a
|
||||
| n ->
|
||||
let b = pow a (n / 2) in
|
||||
b * b * (if n mod 2 = 0 then 1 else a)
|
||||
|
||||
let rec powmod a d = function
|
||||
| 0 -> 1
|
||||
| 1 -> a mod d
|
||||
| n ->
|
||||
let b = (powmod a d (n / 2)) mod d in
|
||||
(((b * b) mod d) * (if n mod 2 = 0 then 1 else a)) mod d
|
||||
3
lib/utility/utility.mli
Normal file
3
lib/utility/utility.mli
Normal file
@ -0,0 +1,3 @@
|
||||
val pow : int -> int -> int
|
||||
|
||||
val powmod : int -> int -> int -> int
|
||||
Reference in New Issue
Block a user