What is the difference between saturation and wrapping for integers?
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    MathWorks Support Team
    
 il 4 Dic 2019
  
    
    
    
    
    Risposto: MathWorks Support Team
    
 il 2 Mar 2020
            What is the difference between saturation and wrapping for integers?
Risposta accettata
  MathWorks Support Team
    
 il 4 Dic 2019
        By default (and when the "Saturation on integer overflow" is checked in MATLAB coder settings), when an arithmetic operation involving integers exceeds the maximum or minimum value, the result is set to the maximum or minimum value. This is known as "saturation"
For example, if we consider 8-bit signed integers with a maximum value of 127 and a minimum value of -128:
>> x = int8(127) + 1
x =
    int8
    127
>> x = int8(-128) - 1
x =
    int8
    -128
>> x = int8(-128) - 8
x =
    int8
    -128
When the "Saturation on integer overflow" property is unchecked, then any amount that overflows or exceeds the maximum or minimum value is wrapped around to the opposite extreme. This is known as "wrapping". For example:
>> x = int8(127) + 1
x =
    int8
    -128
>> x = int8(-128) - 1
x =
    int8
    127
>> x = int8(-128) - 8
x =
    int8
    120
Please note that this checkbox applies only to MATLAB code generation, and not to executing MATLAB files or executing MATLAB commands in the Command Window. For more information regarding this behavior, see the following documentation:
0 Commenti
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
