Skip to content
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

Do not force 32 bits in JS math operations #1143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Do not force 32 bits in JS math operations
The "n | 0" is a hack to truncate numbers, but it forces n to 32 bits, which is inconsistent with the expected precision of 54 integer bits using the JS backend. For example, truncate(2147483648) yields -2147483648 (negative), and similarly, 21474836481 // 10 yields -2147483648.
  • Loading branch information
richcarl committed Oct 9, 2023
commit c02dca4e2a04a8958a4c84b5922f400aa8190193
4 changes: 2 additions & 2 deletions src/Elm/Kernel/Basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _Basics_add = F2(function(a, b) { return a + b; });
var _Basics_sub = F2(function(a, b) { return a - b; });
var _Basics_mul = F2(function(a, b) { return a * b; });
var _Basics_fdiv = F2(function(a, b) { return a / b; });
var _Basics_idiv = F2(function(a, b) { return (a / b) | 0; });
var _Basics_idiv = F2(function(a, b) { return Math.trunc(a / b); });
var _Basics_pow = F2(Math.pow);

var _Basics_remainderBy = F2(function(b, a) { return a % b; });
Expand Down Expand Up @@ -45,7 +45,7 @@ var _Basics_atan2 = F2(Math.atan2);
// MORE MATH

function _Basics_toFloat(x) { return x; }
function _Basics_truncate(n) { return n | 0; }
function _Basics_truncate(n) { return Math.trunc(n); }
function _Basics_isInfinite(n) { return n === Infinity || n === -Infinity; }

var _Basics_ceiling = Math.ceil;
Expand Down
Loading