Skip to content

Commit

Permalink
fix/bug-59814 (#634)
Browse files Browse the repository at this point in the history
[se] Fix bug 59814
Co-authored-by: GoshaZotov <[email protected]>
Co-committed-by: GoshaZotov <[email protected]>
  • Loading branch information
GoshaZotov committed Feb 4, 2025
1 parent 57a1964 commit c259377
Show file tree
Hide file tree
Showing 2 changed files with 403 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cell/model/FormulaObjects/mathematicFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,7 @@ function (window, undefined) {
return truncate(quotient + nolpiat) * significance;
}

function roundHelper(number, num_digits) {
function roundHelper(number, decimals) {
if (num_digits > AscCommonExcel.cExcelMaxExponent) {
if (Math.abs(number) < 1 || num_digits < 1e10) // The values are obtained experimentally
{
Expand All @@ -4084,16 +4084,20 @@ function (window, undefined) {
return new cNumber(0);
}

var significance = SignZeroPositive(number) * Math.pow(10, -truncate(num_digits));
const EPSILON = 1e-14;

number += significance / 2;
// ->integer
decimals = decimals >> 0;

if (number / significance == Infinity) {
return new cNumber(number);
}
const multiplier = Math.pow(10, decimals);
const shifted = Math.abs(number) * multiplier;

return new cNumber(Floor(number, significance));
// Add epsilon to handle floating point precision issues (1.005 case)
const compensated = shifted + EPSILON;
const rounded = Math.floor(compensated + 0.5);

let result = (Math.sign(number) * rounded) / multiplier;
return new cNumber(result);
}

var arg0 = arg[0], arg1 = arg[1];
Expand Down
Loading

0 comments on commit c259377

Please sign in to comment.