ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

ARM JIT: `Math.round` is buggy for integers between 2**52+1 and 2**53-1

Open Yaffle opened this issue 10 years ago • 8 comments

Math.round is implemented like Math.floor(x + 0.5) seems, and so is buggy for some values:

Math.round(0.5 - Number.EPSILON / 4) - should give 0, not 1 Math.round(1 / Number.EPSILON + 1) - should give 1 / Number.EPSILON + 1 Math.round(-(1 / Number.EPSILON + 1)) - should give 1 / Number.EPSILON + 1

Actually, there is no need to "round" values which has absolute value >= 1 / Number.EPSILON.

see https://github.com/tc39/test262/blob/26e6fd7c1779a63913cc7720cbc6c87b3b7b3285/test/built-ins/Math/round/S15.8.2.15_A7.js

Yaffle avatar Jan 22 '16 15:01 Yaffle

Neither of the ES5 and ES6 standards says anything special about the value of Math.round(1 / Number.EPSILON + 1). Please see http://www.ecma-international.org/ecma-262/5.1/#sec-15.8.2.15, and http://www.ecma-international.org/ecma-262/6.0/#sec-math.round

mcfi avatar Jan 22 '16 16:01 mcfi

@mcfi ,

  1. Returns the Number value that is closest to x and is equal to a mathematical integer
  2. see Note 2 Math.round(x) may also differ from the value of Math.floor(x+0.5)because of internal rounding when computing x+0.5.

Yaffle avatar Jan 22 '16 17:01 Yaffle

@Yaffle , I see what you mean, thank!

mcfi avatar Jan 22 '16 19:01 mcfi

@mcfi , thank you, I wan unclear

Yaffle avatar Jan 22 '16 20:01 Yaffle

Note this now only needs to be fixed for ARM JIT.

MikeHolman avatar Feb 03 '16 23:02 MikeHolman

@sigatrev does this issue exists for arm64?

agarwal-sandeep avatar Mar 21 '18 23:03 agarwal-sandeep

@agarwal-sandeep I am not seeing this repro on my arm64 machine using either ARM or ARM64 binaries

sigatrev avatar Mar 22 '18 00:03 sigatrev

@sigatrev should we close as no repro?

dilijev avatar May 02 '18 16:05 dilijev