Converting floating point to fixed point

后端 未结 6 1844
耶瑟儿~
耶瑟儿~ 2020-12-23 12:13

In C++, what\'s the generic way to convert any floating point value (float) to fixed point (int, 16:16 or 24:8)?

EDIT: For clarification, fixed-poin

6条回答
  •  一整个雨季
    2020-12-23 13:09

    This is fine for converting from floating point to integer, but the O.P. also wanted fixed point.

    Now how you'd do that in C++, I don't know (C++ not being something I can think in readily). Perhaps try a scaled-integer approach, i.e. use a 32 or 64 bit integer and programmatically allocate the last, say, 6 digits to what's on the right hand side of the decimal point.

提交回复
热议问题