cosine icon indicating copy to clipboard operation
cosine copied to clipboard

Definition of modd leads to crahes for negative angles

Open abaghiyan opened this issue 3 years ago • 0 comments

Dear Authors,

Thank you for the nice work.

The definition of modd in the form #define modd(x, y) ((x) - (int)((x) / (y)) * (y)) (process time is about 0.326 s for cos_table_0_0001 and 0.5 s for cos_table_0_0001_LERP on my laptop) leads to crashes for negative values. I suggest to change it to #define modd(x, y) ((x) - (int)floor((x) / (y)) * (y)) which is slower (process time is about 0.599 s for cos_table_0_0001 and 0.725 s for cos_table_0_0001_LERP on my laptop) or faster version of previous - #define modd(x, y) ((x) - ((x >= 0) * (int)((x) / (y)) * (y) + (x < 0) * ((int)((x) / (y)) - 1) * (y))) (process time is about 0.556 s for cos_table_0_0001 and 0.652 s for cos_table_0_0001_LERP on my laptop) or even faster and nicer version - #define modd(x, y) ((x) - ((int)((x) / (y)) - signbit(x)) * (y)) (process time is about 0.389 s for cos_table_0_0001 and 0.521 s for cos_table_0_0001_LERP on my laptop), while the process time of cos_math_h is about 0.819 s.

Regards, Aram

abaghiyan avatar Jul 07 '21 17:07 abaghiyan