mpv
mpv copied to clipboard
commands: make sure add_float() argument is treated as a float
The input value to be added in add_float is a double, and added as a double. Since not all double values have a corresponding float32 value, make sure to use it's nearest float if it is not exactly representable in a float before performing the addition.
This guarantees that the result of adding a float and it's inverse is 0.
Previously: float x = 1.0 // (stored as 0.100001998) add_float(&x, -1.0) // (0.100001998 + -0.10000000000000001) x != 0
Now: float x = 1.0 //(stored as 0.100001998) add_float(&x, -1.0) //(0.100001998 + -0.100001998) x == 0
This was discovered because "Sub delay" was displaying "-0.0" when adding and then subtracting 100ms, so the end result was -0.00000145... Should also fix it for audio delay and all the options that store it's value as a float.
Download the artifacts for this pull request:
This change is little bit meh. It would be nicer to not involve double conversions at all in float cases. But I guess won't harm. I'd adjust other float operations too with the same treatment.