How to replace the i64::from( vol as i32) part with something platform (32/64 bit) agnostic
that is what I am doing currently - mapping a f64 based on the actual range of the device.
But I am stuck at making it work with both 64/32 bit proof:
For example I have this for 32bit
But I am stuck at making it work with both 64/32 bit proof:
For example I have this for 32bit
let vol_db = i64::from((self.pvol(vol, 0x0000, 0xFFFF).log10() * 6000.0).floor() as i32)But want replace the i64::from( vol as i32) part with something platform (32/64 bit) agnostic
+ self.params.max_db.0;
No any search results
You already invited:
4 Answers
MarcoFalke
Upvotes from:
Either the volume spans a 32 bit range, or a 64 bit range
The size of a pointer shouldn’t affect that... 32 bit systems can do 64 bit arithmetic too
Benny
Upvotes from:
Otherwise, if you need 64 bits for accuracy, use 64 bits everywhere.
Dmitry
Upvotes from:
At least on the Rust side you have the opportunity to expose it consistently
i64 would support a c_long on any platform targetted by Rust; on 32-bit platforms you could have value >> 32 as c_long, and value as c_long on 64 bits
Or do it with 0.0 <= f64 < 1.0 and map to c_long as appropriate
Or if you want to keep fidelity with the underling ALSA lib, expose c_long on the Rust side and have the user deal with it
Aamir
Upvotes from:
Unless performance is critical, I'd do the math with the same amount of space always (i64 in this case, I guess)
I rather suspect that if you're calling audio libs, doing a little 64-bit math on a 32 bit platform is not going to be the bottleneck.