miklhh / WiseMansFixedPoint

Improved header only fixed point arithmetic library.
1 stars 0 forks source link

Add support for unsigned fixed point numbers #2

Open miklhh opened 3 years ago

miklhh commented 3 years ago

As of right now, the support for unsigned number has been put on hold while we try to figure out what to do with arithmetic between signed and unsigned numbers. To minimize code duplication, this library tries to implement generic arithmetic functions that can be used by both signed and unsigned numbers. Less code, less to maintain, easier to keep sane and functioning.

Before this issue can be considered resolved, especially make sure the following have been taken in consideration:

miklhh commented 3 years ago

Regarding what to do with arithmetic between signed and unsigned numbers, I'm currently thinking of disabling support of it completely, requiring users to explicitly convert one number to a common type before performing arithmetic. This would save some code writing and this is how the problem is solved in the VHDL language. We prefer to minimize implicit type conversion which would be necessary otherwise.

The only real reason I can think of why not to go down this path, is that C++ uses usual arithmetic conversion to implicitly convert signed numbers to unsigned when stumbling on an expression that requires such. Then again all compilers today will warn their users (with -Wall enabled) that binary arithmetic between signed and unsigned types are dangerous. So maybe we really should just disable it completely.

miklhh commented 3 years ago

The problem with arithmetic has now been solved by disallowing it completely. Where applicable, all arithmetic will require the user to explicitly type convert left or right hand side to a common type. This is ensured through a static_assert such that users gets a warning during compile time.