Quantcast
Channel: EngineerZone: Message List
Viewing all articles
Browse latest Browse all 28044

Re: Saturation vs. Overflow

$
0
0

Hi Daniel,

 

There is no need for such an option since any built-in operators for the type fract16, fract2x16 and fract32 use saturating arithmetic by default:

 

#include <fract_math.h>

 

fract16  sum_16 (fract16 x, fract16 y)

{

  return add_fr1x16 (x, y);             // the compiler will generate an instruction of the form R0.H = R1.L + R0.L (S);

}

 

The same applies to any of the fractional DSP library functions as well as the embedded C type – they too use saturating arithmetic.

 

Thus the only time you will need to explicitly specify saturation is when writing your own assembly code.

 

Please note that if you re-write the above example using integer arithmetic, no saturation will be used (the standard behavior for integral C types):

 

short  sum_16 (short x, short y)

{

  return (x+ y);           // R0.H = R1.L + R0.L (NS); will be generated

}

 

Best Regards,

Andreas


Viewing all articles
Browse latest Browse all 28044

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>