authorgravatar for adambgoertz@gmail.comAdam Goertz <adambgoertz@gmail.com> 2023-07-29 02:55:25+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-02 12:00:14-07:00
log9e19969e09ffee8aca39f28a42d566cc62b479d6
tree794fd9d774e0ee7e7d3f6ad80d092697b045e86b
parent4d7dd1689fb1e7344fa9e4ca80394369569d0379

Remove math.ln in favor of `@log`


3 files changed, 1 insertions(+), 37 deletions(-)

CMakeLists.txt-1
...@@ -273,7 +273,6 @@ set(ZIG_STAGE2_SOURCES...@@ -273,7 +273,6 @@ set(ZIG_STAGE2_SOURCES
273 "${CMAKE_SOURCE_DIR}/lib/std/math/frexp.zig"273 "${CMAKE_SOURCE_DIR}/lib/std/math/frexp.zig"
274 "${CMAKE_SOURCE_DIR}/lib/std/math/isinf.zig"274 "${CMAKE_SOURCE_DIR}/lib/std/math/isinf.zig"
275 "${CMAKE_SOURCE_DIR}/lib/std/math/isnan.zig"275 "${CMAKE_SOURCE_DIR}/lib/std/math/isnan.zig"
276 "${CMAKE_SOURCE_DIR}/lib/std/math/ln.zig"
277 "${CMAKE_SOURCE_DIR}/lib/std/math/log.zig"276 "${CMAKE_SOURCE_DIR}/lib/std/math/log.zig"
278 "${CMAKE_SOURCE_DIR}/lib/std/math/log10.zig"277 "${CMAKE_SOURCE_DIR}/lib/std/math/log10.zig"
279 "${CMAKE_SOURCE_DIR}/lib/std/math/log2.zig"278 "${CMAKE_SOURCE_DIR}/lib/std/math/log2.zig"
lib/std/math.zig+1-2
...@@ -244,7 +244,6 @@ pub const atan2 = @import("math/atan2.zig").atan2;...@@ -244,7 +244,6 @@ pub const atan2 = @import("math/atan2.zig").atan2;
244pub const hypot = @import("math/hypot.zig").hypot;244pub const hypot = @import("math/hypot.zig").hypot;
245pub const expm1 = @import("math/expm1.zig").expm1;245pub const expm1 = @import("math/expm1.zig").expm1;
246pub const ilogb = @import("math/ilogb.zig").ilogb;246pub const ilogb = @import("math/ilogb.zig").ilogb;
247pub const ln = @import("math/ln.zig").ln;
248pub const log = @import("math/log.zig").log;247pub const log = @import("math/log.zig").log;
249pub const log2 = @import("math/log2.zig").log2;248pub const log2 = @import("math/log2.zig").log2;
250pub const log10 = @import("math/log10.zig").log10;249pub const log10 = @import("math/log10.zig").log10;
...@@ -395,7 +394,6 @@ test {...@@ -395,7 +394,6 @@ test {
395 _ = hypot;394 _ = hypot;
396 _ = expm1;395 _ = expm1;
397 _ = ilogb;396 _ = ilogb;
398 _ = ln;
399 _ = log;397 _ = log;
400 _ = log2;398 _ = log2;
401 _ = log10;399 _ = log10;
...@@ -438,6 +436,7 @@ pub const min = @compileError("deprecated; use @min instead");...@@ -438,6 +436,7 @@ pub const min = @compileError("deprecated; use @min instead");
438pub const max = @compileError("deprecated; use @max instead");436pub const max = @compileError("deprecated; use @max instead");
439pub const min3 = @compileError("deprecated; use @min instead");437pub const min3 = @compileError("deprecated; use @min instead");
440pub const max3 = @compileError("deprecated; use @max instead");438pub const max3 = @compileError("deprecated; use @max instead");
439pub const ln = @compileError("deprecated; use @log instead");
441440
442/// Limit val to the inclusive range [lower, upper].441/// Limit val to the inclusive range [lower, upper].
443pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {442pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
lib/std/math/ln.zig deleted-34
...@@ -1,34 +0,0 @@
1const std = @import("../std.zig");
2const math = std.math;
3const testing = std.testing;
4
5/// Returns the natural logarithm of x.
6///
7/// Special Cases:
8/// - ln(+inf) = +inf
9/// - ln(0) = -inf
10/// - ln(x) = nan if x < 0
11/// - ln(nan) = nan
12/// TODO remove this in favor of `@log`.
13pub fn ln(x: anytype) @TypeOf(x) {
14 const T = @TypeOf(x);
15 switch (@typeInfo(T)) {
16 .ComptimeFloat => {
17 return @as(comptime_float, @log(x));
18 },
19 .Float => return @log(x),
20 .ComptimeInt => {
21 return @as(comptime_int, @floor(@log(@as(f64, x))));
22 },
23 .Int => |IntType| switch (IntType.signedness) {
24 .signed => @compileError("ln not implemented for signed integers"),
25 .unsigned => return @as(T, @floor(@log(@as(f64, x)))),
26 },
27 else => @compileError("ln not implemented for " ++ @typeName(T)),
28 }
29}
30
31test "math.ln" {
32 try testing.expect(ln(@as(f32, 0.2)) == @log(0.2));
33 try testing.expect(ln(@as(f64, 0.2)) == @log(0.2));
34}