mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-15 23:37:42 -04:00
zig: replace the deprecated @intFromFloat with @trunc
Zig 0.16 forwards the result type through the unary float builtins, so @trunc produces the integer directly and @intFromFloat is deprecated as redundant with it. Every site was a truncating cast, or already held an integral value, so the behaviour is unchanged.
This commit is contained in:
1 parent
a1c4a67c08
commit
da8aa307a6
9 files changed
+13
-13
No files matched your search
@@ -201,7 +201,7 @@ pub const RGBA = packed struct(u32) {
|
||||
|
||||
pub fn init(r: u8, g: u8, b: u8, a: f32) RGBA {
|
||||
const clamped = std.math.clamp(a, 0, 1);
|
||||
return .{ .r = r, .g = g, .b = b, .a = @intFromFloat(clamped * 255) };
|
||||
return .{ .r = r, .g = g, .b = b, .a = @trunc(clamped * 255) };
|
||||
}
|
||||
|
||||
/// Finds a color by its name.
|
||||
|
||||
@@ -612,7 +612,7 @@ fn consumeNumeric(self: *Tokenizer) Token {
|
||||
break :blk std.math.minInt(i32);
|
||||
}
|
||||
|
||||
break :blk @as(i32, @intFromFloat(value));
|
||||
break :blk @as(i32, @trunc(value));
|
||||
} else null;
|
||||
|
||||
if (!self.isEof() and self.nextByteUnchecked() == '%') {
|
||||
|
||||
@@ -312,7 +312,7 @@ pub fn triggerMouseWheel(frame: *Frame, x: f64, y: f64, delta_x: f64, delta_y: f
|
||||
|
||||
fn deltaToScroll(d: f64) i32 {
|
||||
if (std.math.isNan(d)) return 0;
|
||||
return @intFromFloat(std.math.clamp(d, std.math.minInt(i32), std.math.maxInt(i32)));
|
||||
return @trunc(std.math.clamp(d, std.math.minInt(i32), std.math.maxInt(i32)));
|
||||
}
|
||||
|
||||
// callback when the "click" event reaches the frame.
|
||||
|
||||
@@ -405,7 +405,7 @@ fn clampLongLong(value: f64) i64 {
|
||||
if (@abs(value - @trunc(value)) == 0.5 and @mod(rounded, 2) != 0) {
|
||||
rounded -= std.math.sign(value);
|
||||
}
|
||||
return @intFromFloat(rounded);
|
||||
return @trunc(rounded);
|
||||
}
|
||||
|
||||
/// Returns the size of the Blob in bytes.
|
||||
|
||||
@@ -1839,7 +1839,7 @@ pub fn scrollIntoView(self: *Element, opts: ?ScrollIntoViewOpts, frame: *Frame)
|
||||
// Positions come from the faux-layout document position (top = preorder
|
||||
// depth-scaled y), the same source getBoundingClientRect uses.
|
||||
const y = calculateDocumentPosition(self.asNode());
|
||||
frame.window.scrollTo(.{ .x = 0 }, @intFromFloat(@max(0, y)), frame) catch {};
|
||||
frame.window.scrollTo(.{ .x = 0 }, @trunc(@max(0, y)), frame) catch {};
|
||||
}
|
||||
|
||||
const ScrollToOpts = union(enum) {
|
||||
|
||||
@@ -261,7 +261,7 @@ pub fn maybeBumpGenerator(self: *Engine, store_id: i64, key: f64) !void {
|
||||
|
||||
// Cap at 2^53, the largest integer the generator tracks per spec.
|
||||
const capped = @min(@floor(key), 9007199254740992);
|
||||
const want: i64 = @intFromFloat(capped + 1);
|
||||
const want: i64 = @trunc(capped + 1);
|
||||
try self.conn.exec(
|
||||
"update idb_object_stores set key_generator = ?2 where id = ?1 and key_generator < ?2",
|
||||
.{ store_id, want },
|
||||
|
||||
@@ -231,19 +231,19 @@ fn substringFn(arena: Allocator, args: []const result.Result) Error![]const u8 {
|
||||
if (std.math.isNan(len_raw)) return "";
|
||||
const len = roundHalfToPosInf(len_raw);
|
||||
const sum = start - 1 + len;
|
||||
// -inf + inf is NaN; @intFromFloat(NaN) is illegal behavior.
|
||||
// -inf + inf is NaN, and NaN to integer is illegal behavior.
|
||||
if (std.math.isNan(sum)) return "";
|
||||
const si_f = @max(start - 1, 0);
|
||||
const ei_f = @min(sum, s_len);
|
||||
if (si_f >= ei_f) return "";
|
||||
const si: usize = @intFromFloat(si_f);
|
||||
const ei: usize = @intFromFloat(ei_f);
|
||||
const si: usize = @trunc(si_f);
|
||||
const ei: usize = @trunc(ei_f);
|
||||
return s[si..ei];
|
||||
}
|
||||
|
||||
const si_f = @max(start - 1, 0);
|
||||
if (si_f >= s_len) return "";
|
||||
const si: usize = @intFromFloat(si_f);
|
||||
const si: usize = @trunc(si_f);
|
||||
return s[si..];
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ pub fn numberToString(arena: Allocator, n: f64) error{OutOfMemory}![]const u8 {
|
||||
if (std.math.isNegativeInf(n)) return "-Infinity";
|
||||
if (n == 0) return "0"; // covers +0 and -0
|
||||
if (@trunc(n) == n and n >= -9.007199254740992e15 and n <= 9.007199254740992e15) {
|
||||
return std.fmt.allocPrint(arena, "{d}", .{@as(i64, @intFromFloat(n))});
|
||||
return std.fmt.allocPrint(arena, "{d}", .{@as(i64, @trunc(n))});
|
||||
}
|
||||
return std.fmt.allocPrint(arena, "{d}", .{n});
|
||||
}
|
||||
|
||||
@@ -537,8 +537,8 @@ fn getBoxModel(cmd: *CDP.Command) !void {
|
||||
.padding = zero,
|
||||
.border = zero,
|
||||
.margin = zero,
|
||||
.width = @intFromFloat(rect.width),
|
||||
.height = @intFromFloat(rect.height),
|
||||
.width = @trunc(rect.width),
|
||||
.height = @trunc(rect.height),
|
||||
} }, .{});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user