summaryrefslogblamecommitdiff
path: root/tests/source/limiter.scade
blob: 05cb2b76b067b19024c17ee702963ee9eca0cf76 (plain) (tree)
1
2
3
4
5
6
7





                                                      
                                             










                                                          
                                                                             


                          
const bound: int = 128;

node limiter(x: int; d: int) returns (probe y: int)
    var s, r: int;
    let
        assume in_bounded: x >= -bound and x <= bound;
        assume d_bounded: d >= 0 and d <= 16;
        guarantee out_bounded: y >= -bound and y <= bound;
        s = 0 -> pre y;
        r = x - s;
        y = if r <= -d then s - d
            else if r >= d then s + d
            else x;
    tel

node test(i: int) returns(a, b, c: int; exit: bool)
    let
        exit = i >= 30;
        a = (i * 21 + 122) mod (2 * bound + 1) - bound;  -- not really random
        b = 16;
        c = limiter(a, b);
    tel