Zig: make @mulAdd support integers, comptime integers, and comptime floats, and no explicit type parameter

Created on 26 Sep 2019  路  3Comments  路  Source: ziglang/zig

I propose to make @mulAdd more like the rest of the math operators built into the language, such as +. This would use Peer Type Resolution to chose a type, just like if you did a + b (except there are 3 values instead of 2).

I see no reason to limit this to floats; it should work just fine for integers too. This will make it more friendly in generic code.

proposal

Most helpful comment

Here's my counter-proposal, let's add a fn fma(a: var, b: var, c: var) @TypeOf(a, b, c) to std.math to handle the comptime and int cases and have it use @mulAdd on floats/vector of floats.

@mulAdd is a low-level builtin that has everything to do with rounding problems so extending it to other types makes little sense IMO.

All 3 comments

What about all the other float operations?

Here's my counter-proposal, let's add a fn fma(a: var, b: var, c: var) @TypeOf(a, b, c) to std.math to handle the comptime and int cases and have it use @mulAdd on floats/vector of floats.

@mulAdd is a low-level builtin that has everything to do with rounding problems so extending it to other types makes little sense IMO.

related #4466

Was this page helpful?
0 / 5 - 0 ratings