Documentation for std.math.ldexp

Can somebody explain to me why std.math.ldexp shows up twice in the docs? I have not seen that elsewhere.

Curious,
s.

2 Likes

No hard proof to back it up, but I think the documentation generator might be confused by the sources also containing scalbn, which is actually just an alias for ldexp in Zig. You’ll notice that scalbn is missing from the docs, even though it does exist in the sources.

std/math/scalbn.zig:

const std = @import("std");
const expect = std.testing.expect;

/// Returns a * FLT_RADIX ^ exp.
///
/// Zig only supports binary base IEEE-754 floats. Hence FLT_RADIX=2, and this is an alias for ldexp.
pub const scalbn = @import("ldexp.zig").ldexp;

test scalbn {
    // Verify we are using base 2.
    try expect(scalbn(@as(f16, 1.5), 4) == 24.0);
    try expect(scalbn(@as(f32, 1.5), 4) == 24.0);
    try expect(scalbn(@as(f64, 1.5), 4) == 24.0);
    try expect(scalbn(@as(f128, 1.5), 4) == 24.0);
}

std/math.zig:

// (...)
pub const scalbn = @import("math/scalbn.zig").scalbn;
pub const ldexp = @import("math/ldexp.zig").ldexp;
// (...)

Might be worth opening an issue.

EDIT: Reported #36436

1 Like

That makes sense, thanks.

TIL how to hide (documentation for) public functions in zig :slight_smile: