100pah commented on code in PR #21107:
URL: https://github.com/apache/echarts/pull/21107#discussion_r2217334774


##########
src/scale/Log.ts:
##########
@@ -64,9 +64,13 @@ class LogScale extends IntervalScale {
 
         return zrUtil.map(ticks, function (tick) {
             const val = tick.value;
-            let powVal = fixRound(mathPow(base, val));
+            const rawVal = mathPow(base, val);
             let roundingCriterion = null;
 
+            // Fix #21099
+            const precision = numberUtil.getPrecisionSafe(rawVal) || 0;
+            let powVal = parseFloat(fixRound(rawVal, precision as number, 
true));

Review Comment:
   @SihongShen @Ovilia I don't fully understand the purpose of this handling.
   
   If `rawVal` has the fractional part digits <= 20, `rawVal` will  be equal to 
`powVal`, nothing changes.
   Otherwise, if the fractional part digits > 20, the `number.round` method 
internally clamp it to 20, but that doesn't make sense in this scenario and may 
lead incorrect results, e.g, `(1e-40).toFixed(20)` we get `0`.
   
   From my understanding, the "fix round" applied in `src/scale` is meant to 
correct rounding errors introduced by floating-point computation, (such as the 
well-known case where `0.1 + 0.2 === 0.30000000000000004`, when representing 
and calculating decimal fractional number in binary).
   
   But `Math.pow(base, tick.value)` shouldn't suffer from such kind of rounding 
error, because the `Log.ts` guarantees `interval` and `tick.value` to be 
integers, and the `base` is typically an integer as well. They can be exactly 
represented in ieee754 64-bit floating-point number (assume no overflow - this 
is an separate topic).  
   
   Therefore, there is no opportunity for rounding errors to be accumulated 
beyond `Number.EPSILON` and result in a different result when converted back to 
a decimal string.
   (Correct me if I'me wrong.)
   
   Therefore, I think we should just remove this precision and round processing 
here. Just be:
   
   ```js
   let powVal = mathPow(base, val);
   ```
   
   
   



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to