You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/05/24 04:04:33 UTC

[GitHub] [echarts] pissang commented on a change in pull request #15015: Fix: (1) number getPrecisionSafe incorrect on scientific notation like 3.45e-1 (2) stack sum eliminate floating arithmetic problem.

pissang commented on a change in pull request #15015:
URL: https://github.com/apache/echarts/pull/15015#discussion_r637673179



##########
File path: src/util/number.ts
##########
@@ -268,6 +270,20 @@ export function getPercentWithPrecision(valueList: number[], idx: number, precis
     return seats[idx] / digits;
 }
 
+/**
+ * Solve the floating point adding problem like 0.1 + 0.2 === 0.30000000000000004
+ * See <http://0.30000000000000004.com/>
+ */
+export function addSafe(val0: number, val1: number): number {
+    const maxPrecision = Math.max(getPrecisionSafe(val0), getPrecisionSafe(val1));

Review comment:
       Can we use `ROUND_SUPPORTED_PRECISION_MAX` in the https://github.com/apache/echarts/blob/a46d2e668f98b17bbade2573b18aad4b4fb35530/src/util/number.ts#L164
   to avoid infinity loop? That method is much faster.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org