floating_bar
floating_bar copied to clipboard
Use macro to reduce code duplication
Right now the code between r32
and r64
is pretty much the same (as a result of copy-pasting it) except for some modifications to handle larger numbers in r64
. Ideally tho, there should be a macro that handles implementations for both types in order to reduce code reuse and possible inconsistencies between them.
Such a macro should only rely on:
- the name of the type (given to the macro)
- some constants defined specifically for each type:
-
TOTAL_SIZE
– gives the total number of bits of the internal type; e.g. forr32
, it's 32 bits (note: not currently defined in code) -
FRACTION_SIZE
– gives the size of the fraction field
-
Everything else (including other necessary constants) should be derivable from the ones above.