f = x -> sample_resolution_in_unit * x + sample_offset_in_unit
We could use instead f = x -> fma(sample_resolution_in_unit, x, sample_offset_in_unit) (or likely better, muladd, if we were OK with only using fma when available on the hardware, rather than forcing software emulation in that case.)
This would be faster and more accurate, since it avoids the intermediate rounding. Julia will not perform this optimization automatically (at least without @fastmath or such) since the compiler isn't allowed to change the results.
E.g. right now we use
We could use instead
f = x -> fma(sample_resolution_in_unit, x, sample_offset_in_unit)
(or likely better,muladd
, if we were OK with only usingfma
when available on the hardware, rather than forcing software emulation in that case.)This would be faster and more accurate, since it avoids the intermediate rounding. Julia will not perform this optimization automatically (at least without
@fastmath
or such) since the compiler isn't allowed to change the results.