Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace everywhere is_le by is_nn #1262

Closed
Tracked by #1263
ClementWalter opened this issue Jul 12, 2024 · 0 comments · Fixed by #1287
Closed
Tracked by #1263

feat: replace everywhere is_le by is_nn #1262

ClementWalter opened this issue Jul 12, 2024 · 0 comments · Fixed by #1287
Assignees

Comments

@ClementWalter
Copy link
Member

Feature Request

Describe the Feature Request

Functions are defined by

// Returns 1 if a >= 0 (or more precisely 0 <= a < RANGE_CHECK_BOUND).
// Returns 0 otherwise.
@known_ap_change
func is_nn{range_check_ptr}(a) -> felt {
    %{ memory[ap] = 0 if 0 <= (ids.a % PRIME) < range_check_builtin.bound else 1 %}
    jmp out_of_range if [ap] != 0, ap++;
    [range_check_ptr] = a;
    ap += 20;
    let range_check_ptr = range_check_ptr + 1;
    return 1;

    out_of_range:
    %{ memory[ap] = 0 if 0 <= ((-ids.a - 1) % PRIME) < range_check_builtin.bound else 1 %}
    jmp need_felt_comparison if [ap] != 0, ap++;
    assert [range_check_ptr] = (-a) - 1;
    ap += 17;
    let range_check_ptr = range_check_ptr + 1;
    return 0;

    need_felt_comparison:
    assert_le_felt(RC_BOUND, a);
    return 0;
}

// Returns 1 if a <= b (or more precisely 0 <= b - a < RANGE_CHECK_BOUND).
// Returns 0 otherwise.
@known_ap_change
func is_le{range_check_ptr}(a, b) -> felt {
    return is_nn(b - a);
}

so callling directly is_nn(b - a) will save steps related to call and ret.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants