← All examples

Div edges

Edges of div.X / mod.X on numbers with a fraction.

div_edges.zg
# Edges of `div.X` / `mod.X` on numbers with a fraction (owner, 2026-10-02). The quotient is the true
# one, rounded as named (Python's `//` agrees); a remainder that rounds to the divisor itself is 0, so
# it stays below the divisor, checked again at the type's own width (bin32, brain16).
MAIN {
    let 'x': bin64 = 0.00000000000000000001;
    let 'n': bin64 = -0.00000000000000000001;
    let 'two': bin64 = 2.0;
    let 'turn': bin64 = 360.0;
    std::print.useful[('x' div.ceil 'two'), " ", ('x' mod.ceil 'two'), " ", ('n' div.floor 'turn'), " ", ('n' mod.floor 'turn'), newln];
    let 'a': bin32 = -0.000001;
    let 'b': bin32 = 360.0;
    std::print.useful[('a' mod.floor 'b'), newln];
    let 'h': brain16 = -1.0;
    let 'k': brain16 = 360.0;
    let 'one': brain16 = 1.0;
    std::print.useful[('h' mod.floor 'k'), " ", ('one' mod.ceil 'k'), newln];
}
Output
1 0 -1 0
0
0 0