Why are there both std.math.F and @F?

Let F = sin():

const std = @import("std");

pub fn main() void {
    std.debug.print("{}\n", .{std.math.sin(34.56)});
    std.debug.print("{}\n", .{@sin(34.56)});
}

Both print one and the same result value.
Why are there two ways of doing the same?
Is there any difference between std.math.sin() and @sin()?
If @sin() is somehow special, why not use in in std.math.sin()?
I do not understand this duality, could someone explain?
Thanks.

They are the same.

1 Like

Ok, thanks!
But then why @sin() and similar are available for use? Shouldn’t they be removed?

I assume that it’s just to match the other trig functions that aren’t builtins.

I tried

    const x: u8 = 21;
    std.debug.print("{}\n", .{std.math.sin(x)});

got

error: expected vector of floats or float type, found 'u8'
    return @sin(value);

I guess type checks are happening in @sin()?..
Why not in std.math.sin()?..

So std.math.sin() is a wrapper for the corresponding builtin function.
If we’d moved type checking into std.math.F() we would had to do this for every function in this category. Bless me… a mechanism similar to python decorators would be ideal for this, wouldn’t it?

pub inline fn sin(value: anytype) @TypeOf(value) {
    return @sin(value);
}

std.math.sin() just call the @sin()

My guess is that not having a sin function in the math library is a bit odd… where is the sin function, not everyone knows about @F. Sometimes @F is different from F, see @rem vs std.math.rem.