RSI has a nasty amount of code duplication in momentum_backend.c as well as parallel_momentum_backend.c due to its compliance to working with 2 types. In the parallel backend this is tricky to work around due to the pointer math involved in the argument builder (pointer math is illegal with void pointers).
However, some work can be done on the underlying function that does the actual computation in momentum_backend.c. In order to make a generic function without casting to a different type, the only option we have evaluated currently is using a #define template for the body of the RSI loop (the per-period computation). Although not the prettiest, this would significantly reduce the code duplication, as this single group of instructions is repeated 6 times throughout the code (3 per RSI function, and there are 2: float, double).
RSI has a nasty amount of code duplication in
momentum_backend.c
as well asparallel_momentum_backend.c
due to its compliance to working with 2 types. In the parallel backend this is tricky to work around due to the pointer math involved in the argument builder (pointer math is illegal withvoid
pointers).However, some work can be done on the underlying function that does the actual computation in
momentum_backend.c
. In order to make a generic function without casting to a different type, the only option we have evaluated currently is using a#define
template for the body of the RSI loop (the per-period computation). Although not the prettiest, this would significantly reduce the code duplication, as this single group of instructions is repeated 6 times throughout the code (3 per RSI function, and there are 2: float, double).