diff options
author | Domen Kožar <domen@dev.si> | 2017-08-30 14:32:04 +0200 |
---|---|---|
committer | Domen Kožar <domen@dev.si> | 2017-08-30 14:32:27 +0200 |
commit | 97a4088d339f2595fa5722b5aec9a39f08ab560a (patch) | |
tree | 03457ce5d2a54f74afcee5eb732ab4a57b5eb664 /lib | |
parent | 9fd315a62faa9011afb34f1d9e0372ccb3983ab9 (diff) |
Add lib.mod: integer modulus
Diffstat (limited to 'lib')
-rw-r--r-- | lib/trivial.nix | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix index 9ee0549fc0fb..a57cf30d171c 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -70,6 +70,16 @@ rec { min = x: y: if x < y then x else y; max = x: y: if x > y then x else y; + /* Integer modulus + + Example: + mod 11 10 + => 1 + mod 1 10 + => 1 + */ + mod = base: int: base - (int * (builtins.div base int)); + /* Reads a JSON file. */ importJSON = path: builtins.fromJSON (builtins.readFile path); |