Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions std/assembly/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,8 @@ export namespace NativeMath {
// @ts-ignore: decorator
@inline
export function round(x: f64): f64 {
return builtin_copysign<f64>(builtin_floor<f64>(x + 0.5), x);
let roundUp = builtin_ceil<f64>(x);
return select<f64>(roundUp, roundUp - 1.0, roundUp - 0.5 <= x);
}

// @ts-ignore: decorator
Expand Down Expand Up @@ -2732,7 +2733,8 @@ export namespace NativeMathf {
// @ts-ignore: decorator
@inline
export function round(x: f32): f32 {
return builtin_copysign<f32>(builtin_floor<f32>(x + 0.5), x);
let roundUp = builtin_ceil<f32>(x);
return select<f32>(roundUp, roundUp - 1.0, roundUp - 0.5 <= x);
}

// @ts-ignore: decorator
Expand Down
Loading