From 9e19969e09ffee8aca39f28a42d566cc62b479d6 Mon Sep 17 00:00:00 2001 From: Adam Goertz Date: Sat, 29 Jul 2023 02:55:25 +0000 Subject: [PATCH] Remove math.ln in favor of `@log` --- CMakeLists.txt | 1 - lib/std/math.zig | 3 +-- lib/std/math/ln.zig | 34 ---------------------------------- 3 files changed, 1 insertion(+), 37 deletions(-) delete mode 100644 lib/std/math/ln.zig diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bd95fdcc9..0765c5c0c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" diff --git a/lib/std/math.zig b/lib/std/math.zig index 25ecd779e9..6d5faeb7ee 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -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) { diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig deleted file mode 100644 index 65db861587..0000000000 --- a/lib/std/math/ln.zig +++ /dev/null @@ -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)); -}