I just used your code and it works as expected y=2.4181300505093746 x=4.0302167508489575 So either you've not set the sample number correctly, or there is something specific to the browser or operating system that you are using that is causing the issue.
Ooh, what fun. I'm sure you've already figured out that the error is in y: If you manually set y=2.06, you'll get the x value you report.
So the next step is to backtrack and figure out how to arrive at your erroneous y from the given starting values.
:: pause to extract calculator from beneath cat ::
Are you getting
y = 2.057983021710106 ?
That's what you get if d is set to 4 instead of 4.7. There are undoubtedly lots of other ways to get the same result-- but this one's a promising start because it suggests that somewhere else in your code, d is getting converted to Math.floor(d). May as well start with the easiest possibility.