AnsweredAssumed Answered

Floating point signum in SHARC using C

Question asked by JayKirsch on Jun 4, 2012
Latest reply on Jun 6, 2012 by Mitesh



I have an algorithm whose parameter depends on the direction of a signal.


alpha = (sig > sig_prev ? alpha_inc : alpha_dec);

where sig_prev is set to sig at the end of the real-time per-sample code.


It is working correctly, however I am concerned the conditional is taking too many cycles.  It would be nice to modifiy an index an index instead, but I can't find any sign function for the SHARC.


//setup code in main()

alpha_flat = alpha_dec;

alphas_arr[] = {alpha_dec,alpha_flat,alpha_inc};


//real-time per-sample code

index = signum(sig - sig_prev)+1; //is 0 when sig<sig_prev, is 0 when sig==sig_prev, is +1 when sig>sig_prev

alpha = alphas_arr[index];


The problem is "signum()" doesn't exist for SHARC, or at least I can't find it.  This algorithm works great in MATLAB using the sign() function, but need to port it to SHARC.