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

@min and @max should allow any number of arguments and notice integer bounds #14039

Closed
andrewrk opened this issue Dec 22, 2022 · 4 comments · Fixed by #15522
Closed

@min and @max should allow any number of arguments and notice integer bounds #14039

andrewrk opened this issue Dec 22, 2022 · 4 comments · Fixed by #15522
Labels
accepted This proposal is planned. enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andrewrk
Copy link
Member

const std = @import("std");

test "three arguments to @min" {
    var runtime1: usize = 1 << 17;
    const max_ciphertext_len = (1 << 14) + 256;
    var runtime2: u64 = 1 << 33;
    const ciphertext_len: u16 = @min(runtime1, max_ciphertext_len, runtime2);
    try std.testing.expect(ciphertext_len == max_ciphertext_len);
}

This test is expected to pass. Note that there should be no compile error due to coercion to u16 despite the use of runtime-known u64 and usize, because one of the arguments to @min is compile-time known to be within range of u16.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. accepted This proposal is planned. labels Dec 22, 2022
@andrewrk andrewrk added this to the 0.11.0 milestone Dec 22, 2022
@Jarred-Sumner
Copy link
Contributor

will there be other variadic functions or a way to define variadic functions (of comptime-known length, unlike in C)?

@andrewrk
Copy link
Member Author

No. Language builtins are special.

@Snektron
Copy link
Collaborator

There are archs with instructions for 3-way min, so this is a good call 👍

No. Language builtins are special.

I guess there could be other builtins, but i can think of none where this applies

@andrewrk
Copy link
Member Author

@TypeOf accepts any number of arguments

mlugg added a commit to mlugg/zig that referenced this issue Apr 30, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 1, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 1, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 1, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 1, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 1, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 1, 2023
andrewrk pushed a commit to mlugg/zig that referenced this issue May 2, 2023
andrewrk pushed a commit that referenced this issue May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. enhancement Solving this issue will likely involve adding new logic or components to the codebase. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants