MikeLankamp/fpm

Question about having to resort to floats for initialization.

Closed this issue · 1 comments

Hi Mike and thanks for the library!

I am working with a deterministic codebase and I have question about initializing fixed-point numbers without having to resort to floats for initialization. Say I need to init a number to 0.25. I can use a float to init an fpl number like so:

fpm::fixed_16_16 b { 0.25 };

However, here we are using a float to init the value. Now, I don't know the risks of using a float for this when it comes to determinism but it would be nice to avoid floats altogether if possible. Is there a way to init an fpm number using a fraction or something? Eg, the above could be initialized like this:

fpm::fixed_16_16 b;
b.initFraction(1, 4);

Thanks!

Oh, wait a minute. I can just do this:

fpm::fixed_16_16 b = fpm::fixed_16_16{ 1 } / fpm::fixed_16_16{ 4 };

Not sure if this is the most ergonomic/efficient way to init a value but it will do. Closing the issue for now...