Skip to content

Impove nearest operation portable polyfill #2105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2021
Merged
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
10 changes: 5 additions & 5 deletions std/portable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ if (typeof globalScope.ASC_TARGET === "undefined") {

globalScope["floor"] = Math.floor;

// Adopt code from https://github.com/rfk/wasm-polyfill
globalScope["nearest"] = function nearest(value) {
if (Math.abs(value - Math.trunc(value)) === 0.5) {
return 2.0 * Math.round(value * 0.5);
}
return Math.round(value);
const INV_EPS64 = 4503599627370496.0;
const y = Math.abs(value);
return y < INV_EPS64
? Math.abs(y + INV_EPS64 - INV_EPS64) * Math.sign(value)
: value;
};

globalScope["select"] = function select(ifTrue, ifFalse, condition) {
Expand Down