Remove math.ln in favor of @log

This commit is contained in:
Adam Goertz 2023-07-29 02:55:25 +00:00 committed by Andrew Kelley
parent 4d7dd1689f
commit 9e19969e09
3 changed files with 1 additions and 37 deletions

View File

@ -273,7 +273,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/math/frexp.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isinf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isnan.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/ln.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log10.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log2.zig"

View File

@ -244,7 +244,6 @@ pub const atan2 = @import("math/atan2.zig").atan2;
pub const hypot = @import("math/hypot.zig").hypot;
pub const expm1 = @import("math/expm1.zig").expm1;
pub const ilogb = @import("math/ilogb.zig").ilogb;
pub const ln = @import("math/ln.zig").ln;
pub const log = @import("math/log.zig").log;
pub const log2 = @import("math/log2.zig").log2;
pub const log10 = @import("math/log10.zig").log10;
@ -395,7 +394,6 @@ test {
_ = hypot;
_ = expm1;
_ = ilogb;
_ = ln;
_ = log;
_ = log2;
_ = log10;
@ -438,6 +436,7 @@ pub const min = @compileError("deprecated; use @min instead");
pub const max = @compileError("deprecated; use @max instead");
pub const min3 = @compileError("deprecated; use @min instead");
pub const max3 = @compileError("deprecated; use @max instead");
pub const ln = @compileError("deprecated; use @log instead");
/// Limit val to the inclusive range [lower, upper].
pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {

View File

@ -1,34 +0,0 @@
const std = @import("../std.zig");
const math = std.math;
const testing = std.testing;
/// Returns the natural logarithm of x.
///
/// Special Cases:
/// - ln(+inf) = +inf
/// - ln(0) = -inf
/// - ln(x) = nan if x < 0
/// - ln(nan) = nan
/// TODO remove this in favor of `@log`.
pub fn ln(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeInfo(T)) {
.ComptimeFloat => {
return @as(comptime_float, @log(x));
},
.Float => return @log(x),
.ComptimeInt => {
return @as(comptime_int, @floor(@log(@as(f64, x))));
},
.Int => |IntType| switch (IntType.signedness) {
.signed => @compileError("ln not implemented for signed integers"),
.unsigned => return @as(T, @floor(@log(@as(f64, x)))),
},
else => @compileError("ln not implemented for " ++ @typeName(T)),
}
}
test "math.ln" {
try testing.expect(ln(@as(f32, 0.2)) == @log(0.2));
try testing.expect(ln(@as(f64, 0.2)) == @log(0.2));
}