Skip to content

std.math.isInf either should support ComptimeFloat or should have a clearer error message #22107

Open
@ssteinbach

Description

@ssteinbach

Zig Version

0.14.0-dev.2340+182cdf74b

Steps to Reproduce and Observed Behavior

test {
    _ = std.math.isInf(3.0);
}

Produces error:

~/zig/0.14.0-dev.2340+182cdf74b/files/lib/std/math/isinf.zig:8:55: error: access of union field 'float' while field 'comptime_float' is active
    const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits);
                                          ~~~~~~~~~~~~^~~~~~
~/zig/0.14.0-dev.2340+182cdf74b/files/lib/std/builtin.zig:556:18: note: union declared here
pub const Type = union(enum) {
                 ^~~~~
/var/tmp/inftest.zig:21:23: note: called from here
    _ = std.math.isInf(3.0);
        ~~~~~~~~~~~~~~^~~~~

std.math.isFinite produces the same error.

This error is present in zig 0.13.0 as well.

Expected Behavior

Given that std.math.isNan supports ComptimeFloat arguments, I expected std.math.isInf / std.math.isFinite to also support them. If there is a reason why it shouldn't support ComptimeFloat, then a more helpful @compileError() might be helpful. Just flagging this in case it was missed! Thanks all!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions