remove unnecessary call to math.floor in bitcode

This commit is contained in:
Brendan Hansknecht 2023-12-07 17:23:42 -08:00
parent d202b77ae1
commit f738d5a2bf
No known key found for this signature in database
GPG key ID: A199D0660F95F948
2 changed files with 4 additions and 1 deletions

View file

@ -215,7 +215,9 @@ pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8
pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8) void {
comptime var f = struct {
fn func(input: F) callconv(.C) T {
return @as(T, @intFromFloat((math.floor(input))));
// intFromFloat just returns the integer part of the float.
// This means it automatically floors. No need for an explicit call to floor.
return @as(T, @intFromFloat(input));
}
}.func;
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });

View file

@ -1813,6 +1813,7 @@ fn ceiling() {
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn floor() {
assert_evals_to!("Num.floor 1.9f64", 1, i64);
assert_evals_to!("Num.floor -1.9f64", -1, i64);
}
#[test]