-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
size:Stype:enhancementNew feature or requestNew feature or requestversion: minor incrMinor version number increment required. (Change adds new features)Minor version number increment required. (Change adds new features)
Description
I've repeatedly found myself needing to write helper functions such as the following:
int32_t ashr32(int32_t x, right_shift_t shr){
int32_t y;
if(shr >= 0) y = (x >> ( shr) );
else y = (x << (-shr) );
return y;
}
int64_t ashr64(int64_t x, right_shift_t shr){
int64_t y;
if(shr >= 0) y = (x >> ( shr) );
else y = (x << (-shr) );
return y;
}
int32_t float_s32_to_fixed(float_s32_t v, exponent_t output_exp){
right_shift_t shr = output_exp - v.exp;
return ashr32(v.mant, shr);
}
int32_t float_s64_to_fixed(float_s64_t v, exponent_t output_exp){
right_shift_t shr = output_exp - v.exp;
return ashr64(v.mant, shr);
}
int32_t float_to_fixed(float x, exponent_t output_exp){
float_s32_t y = f32_to_float_s32(x);
return float_s32_to_fixed(y, output_exp);
}Including within lib_xcore_math. I believe there are already macros for the arithmetic shifts, but they aren't exposed as part of the public API. These should probably be added.
lin72h
Metadata
Metadata
Assignees
Labels
size:Stype:enhancementNew feature or requestNew feature or requestversion: minor incrMinor version number increment required. (Change adds new features)Minor version number increment required. (Change adds new features)