You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, this isn't a bug. When you assign integers to a fixed, it's giving it the
literal binary representation. It's not particularly pretty but C/C++ are
pretty limited in this regard, there's no way to add in our own number parser
to correctly parse a fixed point number and the only way to accurately
initialize is an int.
I think there's an issue ticket somewhere to make this more clear. If you want
to initialize a number as a float then you'll have to use the conversion
functions.
The integer value 32767 is actually 0.5 in Q16.
Original comment by Flatmush@googlemail.com on 8 Jan 2013 at 3:23
Yeah, to clear things up for anyone else who might read this bug report later,
you need to do it like this:
fix16_t value1 = fix16_from_int(123);
float value2 = fix16_to_float(value1);
For declaring constant values, you can also use shorthand macro F16(), like
this:
fix16_t value3 = F16(1234.53); // Works for int, float, double arguments
Original comment by Petteri.Aimonen on 8 Jan 2013 at 3:33
I would also like to point out that the F16 macro is not part of the code thats
in the downloads section as of 1/8/13 but it is in the latest commit of the
repository.
Original comment by iza...@gmail.com on 8 Jan 2013 at 3:48
Original issue reported on code.google.com by
iza...@gmail.com
on 8 Jan 2013 at 3:14The text was updated successfully, but these errors were encountered: