(Dedicated function for) natural logarithm missing in standard library

Continuing the discussion from Division by zero and Illegal Behavior:

That isn’t quite correct. Apparently @log is the natural logarithm, @log2 is the logarithm to the base 2, and @log10 is the logarithm to the base 10.

While std.math.log2 is the logarithm to the base 2 and std.math.log10 is the logarithm to the base 10, std.math.log is not the natural logarithm, but the logarithm with a to-be-specified base.

Of course you can specify std.math.e manually, but is there a reason for this somewhat inconsistent naming scheme?

It seems a bit weird to me, as we have other functions that specifically target the natural logarithm, e.g. std.math.log1p.

1 Like

Looks like the standard library used to have both std.math.log(base, x) and std.math.ln(x) but that the latter was removed in Remove math.ln in favor of @log by AdamGoertz · Pull Request #16602 · ziglang/zig · GitHub

I agree that it’s confusing that they share the same name but are different APIs. AFAIK all other operations that exist both as std.math functions and builtins mean the same thing.

1 Like

I left a comment in the corresponding issue. Not sure if

  • the inconsistency has been known by the time of the merge
  • my comment to a closed issue would be read

Should I open a new issue on this?

I decided to open a separate issue on this:

(Can be closed, of course, if it’s really intentional.)