about summary refs log tree commit diff
path: root/users/sterni/nix/float/default.nix
blob: ecb6465c88424a66bacdccbf862fd8155bdee336 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{ depot, ... }:

let
  inherit (depot.users.sterni.nix)
    num
    ;
in

rec {
  # In C++ Nix, the required builtins have been added in version 2.4
  ceil = builtins.ceil or (throw "Nix implementation is missing builtins.ceil");
  floor = builtins.floor or (throw "Nix implementation is missing builtins.floor");

  truncate = f: if f >= 0 then floor f else ceil f;
  round = f:
    let
      s = num.sign f;
      a = s * f;
    in
    s * (if a >= floor a + 0.5 then ceil a else floor a);

  intToFloat = i: i * 1.0;
}