diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-14 12:38:56 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-14 12:38:56 -0400 |
| commit | 5919b10048be6efa8c0ca6bcb259706098b2d5ec (patch) | |
| tree | 307c504b85c9aee16602e667db1a5db5c25e1fff /lib | |
| parent | cb3b1dd6ddee65d1811fb4058b5cc0f2c06d0139 (diff) | |
| parent | b2a1b4c085b93d508c51307f40444252b8cd4d52 (diff) | |
| download | zig-5919b10048be6efa8c0ca6bcb259706098b2d5ec.tar.gz zig-5919b10048be6efa8c0ca6bcb259706098b2d5ec.zip | |
Merge pull request #11155 from ziglang/stage2-float-fixes
stage2 float fixes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/math/round.zig | 4 | ||||
| -rw-r--r-- | lib/std/meta.zig | 1 | ||||
| -rw-r--r-- | lib/std/multi_array_list.zig | 2 | ||||
| -rw-r--r-- | lib/std/special/c.zig | 10 |
4 files changed, 15 insertions, 2 deletions
diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig index 7e1ee1ebd1..c948431a35 100644 --- a/lib/std/math/round.zig +++ b/lib/std/math/round.zig @@ -20,6 +20,10 @@ pub fn round(x: anytype) @TypeOf(x) { f32 => round32(x), f64 => round64(x), f128 => round128(x), + + // TODO this is not correct for some targets + c_longdouble => @floatCast(c_longdouble, round128(x)), + else => @compileError("round not implemented for " ++ @typeName(T)), }; } diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 3f3144f0d1..7be06e0fd1 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -930,6 +930,7 @@ test "std.meta.Float" { try testing.expectEqual(f128, Float(128)); } +/// Deprecated. Use `@Vector`. pub fn Vector(comptime len: u32, comptime child: type) type { return @Type(.{ .Vector = .{ diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig index 7d967492e9..53eb8fa352 100644 --- a/lib/std/multi_array_list.zig +++ b/lib/std/multi_array_list.zig @@ -421,7 +421,7 @@ pub fn MultiArrayList(comptime S: type) type { } fn capacityInBytes(capacity: usize) usize { - const sizes_vector: std.meta.Vector(sizes.bytes.len, usize) = sizes.bytes; + const sizes_vector: @Vector(sizes.bytes.len, usize) = sizes.bytes; const capacity_vector = @splat(sizes.bytes.len, capacity); return @reduce(.Add, capacity_vector * sizes_vector); } diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig index db1c56c536..326ca3a8a0 100644 --- a/lib/std/special/c.zig +++ b/lib/std/special/c.zig @@ -98,6 +98,7 @@ comptime { @export(round, .{ .name = "round", .linkage = .Strong }); @export(roundf, .{ .name = "roundf", .linkage = .Strong }); + @export(roundl, .{ .name = "roundl", .linkage = .Strong }); @export(fmin, .{ .name = "fmin", .linkage = .Strong }); @export(fminf, .{ .name = "fminf", .linkage = .Strong }); @@ -575,11 +576,18 @@ fn fabsf(a: f32) callconv(.C) f32 { return math.fabs(a); } +fn roundf(a: f32) callconv(.C) f32 { + return math.round(a); +} + fn round(a: f64) callconv(.C) f64 { return math.round(a); } -fn roundf(a: f32) callconv(.C) f32 { +fn roundl(a: c_longdouble) callconv(.C) c_longdouble { + if (!long_double_is_f128) { + @panic("TODO implement this"); + } return math.round(a); } |
