Library reference

Natural logarithm

Use the natural logarithm to recover the number of continuous growth intervals from a positive ratio.

@log

Simple example

Evaluate the natural logarithm of one.

Start1
Result0
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@log(@as(f64, 1.0))});
}
Output
0
Advertisements

Everyday examples

A classroom culture model grew to twice its starting size. How many natural growth intervals is that?

Start2
Result0.6931471805599453
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@log(@as(f64, 2.0))});
}
Output
0.6931471805599453

A sound signal has the same strength as its reference. What is the natural log of the ratio?

Start1
Result0
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@log(@as(f64, 1.0))});
}
Output
0

A time-lapse model shows a patch four times as large as at the start. What is the natural log of that growth factor?

Start4
Result1.3862943611198906
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@log(@as(f64, 4.0))});
}
Output
1.3862943611198906
Run the example
Terminal
zig run lesson.zig
Official documentation