← All examples

Div lands

Division is exact and checked where it lands, as plus, minus, times and pow are: the smallest int8 divided by -1 is 128, which no int8 holds, but a print takes the true…

div_lands.zg
# Division is exact and checked where it lands, as `plus`, `minus`, `times` and `pow` are (owner, 2026-10-02: a): the
# smallest int8 divided by -1 is 128, which no int8 holds, but a print takes the true answer.
MAIN {
    let 'a': int8 = -128;
    std::print.useful[('a' div.trunc -1), " ", ('a' div.floor -1), " ", ('a' mod.floor -1), newln];
    let 'b': int16 = 'a' div.near -1;     # lands in an int16: fits
    std::print.useful['b', newln];
}
Output
128 128 0
128