Skip to content

Commit dba8ae2

Browse files
author
James Cox-Morton
committed
Add a basic ldexp
Enough to make ziglang#23358 snipped pass
1 parent e28b402 commit dba8ae2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/compiler_rt.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ comptime {
219219
_ = @import("compiler_rt/fmax.zig");
220220
_ = @import("compiler_rt/fmin.zig");
221221
_ = @import("compiler_rt/fmod.zig");
222+
_ = @import("compiler_rt/ldexp.zig");
222223
_ = @import("compiler_rt/log.zig");
223224
_ = @import("compiler_rt/log10.zig");
224225
_ = @import("compiler_rt/log2.zig");

lib/compiler_rt/ldexp.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const std = @import("std");
2+
const expect = std.testing.expect;
3+
const math = std.math;
4+
const common = @import("common.zig");
5+
6+
comptime {
7+
@export(&ldexp, .{ .name = "ldexp", .linkage = common.linkage, .visibility = common.visibility });
8+
}
9+
10+
pub fn ldexp(x: f64, n: i32) callconv(.c) f64 {
11+
return math.scalbn(x, n);
12+
}
13+
14+
test "ldexp_64" {
15+
// Ported from libc-test
16+
// https://repo.or.cz/libc-test.git/blob/HEAD:/src/math/sanity/ldexp.h
17+
try expect(ldexp( -0x1.02239f3c6a8f1p+3, -2) == -0x1.02239f3c6a8f1p+1);
18+
}

0 commit comments

Comments
 (0)