New issue
Advanced search Search tips

Issue 825499 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Mar 2018
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

Unexpected frequency value on OscillatorNode

Reported by mvattu...@gmail.com, Mar 24 2018

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

Steps to reproduce the problem:
1. Open Chrome, go into DevTools Console
2. Create an oscillator and set frequency to a decimal:
```
const audioCtx = new AudioContext();
const osc = audioCtx.createOscilator();
osc.frequency.value = 82.41 // E2
osc.frequency.value // returns 82.41000366210938
```

What is the expected behavior?
I would expect to see 82.41 as the frequency value when getting it

What went wrong?
I see 82.41000366210938 set as the frequency instead

Did this work before? N/A 

Does this work in other browsers? No
 Follow the same steps on Firefox and you'll see the same issue as what is on Chrome.

Chrome version: 65.0.3325.181  Channel: stable
OS Version: OS X 10.13.3
Flash Version: 

I've also tried using `setValueAtTime` since that is the way it _should_ be handled, but I've also noticed issues there. Same with trying to use `toFixed(2)`.
Maybe I'm fundamentally misunderstanding something about how IEEE 754 works?
 

Comment 1 by rtoy@chromium.org, Mar 24 2018

Status: WontFix (was: Unconfirmed)
All AudioParam values are (single) floats.  Javascript uses double floats.  The difference you see it the conversion for 82.41 as a double (which can't be represented as exactly as a double-float)  to a single-float for the AudioParam, which you read back into a double-float.

To see the effect look at what Math.fround(82.41) produces.  

This is WAI and is how IEEE 754 works.

Comment 2 by mvattu...@gmail.com, Mar 25 2018

Ah okay, pardon my ignorance. I'll read up on that, I had a feeling it was a gotcha rather than a bug.

Thanks!

Comment 3 by rtoy@chromium.org, Mar 27 2018

You can look at the IEE754 spec itself or maybe the classic Goldberg article: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Comment 4 by mvattu...@gmail.com, Mar 27 2018

Thanks for the link. This all has been super informative. 

Sign in to add a comment