New issue
Advanced search Search tips

Issue 681524 link

Starred by 2 users

Issue metadata

Status: Duplicate
Merged: issue 691345
Owner: ----
Closed: Feb 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

floating point inaccuracy with mod

Reported by 8998...@gmail.com, Jan 16 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

Steps to reproduce the problem:
Execute the next line in JavaScript and for some people, it is NaN:

1.7976931348623158e308 % 1.698093170258119e-130

Proof: http://i.imgur.com/wGe5EJe.png

What is the expected behavior?
I am not sure what the correct result should be, but certainly not NaN. In Firefox, a friend's Chrome browser and C, it is 6.124987715625227e-132:

#include <math.h>
#include <stdio.h>

int main(){
	printf("%g\n", fmod(1.7976931348623158e308, 1.698093170258119e-130));
	printf("%g\n", remainder(1.7976931348623158e308, 1.698093170258119e-130));
	return 0;
}

What went wrong?
The result in Chrome is NaN.

Did this work before? N/A 

Chrome version: 55.0.2883.87  Channel: stable
OS Version: 6.3
Flash Version: Shockwave Flash 24.0 r0

1.7976931348623158e308 is Number.MAX_VALUE. The value of 1.698093170258119e-130 seems to be crucial down to the last bit. It does not seem to be a floating point parsing issue since it also happens when the number is constructed from bytes:

var view = new DataView(new ArrayBuffer(8))
view.setUint32(0, 0x24fe21ff)
view.setUint32(4, 0xcc3a9351)
var x = view.getFloat64(0)
console.log("Number is 1.698093170258119e-130 as expected:", x)
console.log("This should not be NaN, but it is:", Number.MAX_VALUE % x)
 
Components: -Blink Blink>JavaScript

Comment 2 by ajha@chromium.org, Jan 16 2017

Labels: Needs-Triage-M55

Comment 3 by 8998...@gmail.com, Jan 16 2017

I could reproduce the bug by compiling the C code with an online Visual Studio compiler instead of gcc: http://rextester.com/CUXF63188

However, I am unable to report the bug there since their webform is garbage and does not let me, so if this issue should be fixed, someone else has to report it to Microsoft.
Cc: kkaluri@chromium.org
Labels: Needs-Feedback
Tested this issue on windows 10 with chrome version #55.0.2883.87
On pasting below code into the console, observed the output as "6.124987715625227e-132" but not as Nan

code
-----
var view = new DataView(new ArrayBuffer(8))
view.setUint32(0, 0x24fe21ff)
view.setUint32(4, 0xcc3a9351)
var x = view.getFloat64(0)
console.log("Number is 1.698093170258119e-130 as expected:", x)
console.log("This should not be NaN, but it is:", Number.MAX_VALUE % x)

Attaching the screen-cast for your reference, could you please look into it and let us know your observations.
 


Issue 681524.mp4
956 KB View Download
Status: WontFix (was: Unconfirmed)
Just to confirm: If you build it yourself with VS, you get this error?

Comment 6 by 8998...@gmail.com, Feb 9 2017

to hablich@chromium.org:
I am referring to the C code in the initial post that is also visible if you click the link in my previous comment (same link again): http://rextester.com/CUXF63188
If you click on the button labeled "Run it", you will see that the result is "-nan(ind)", which is wrong.

A friend was able to confirm the bug in visual studio 2015, but not in visual studio 2017.

The Chrome binary I am using was built with visual studio 2015, according to the last line in chrome://version/

Compiling Chrome with a more recent version of visual studio might fix this issue.

Mergedinto: 691345
Status: Duplicate (was: WontFix)

Sign in to add a comment