Skip to content

Commit

Permalink
Add lib.mod: integer modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Aug 30, 2017
1 parent 9fd315a commit 97a4088
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/trivial.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 97a4088

Please sign in to comment.