Matlab int16 emulation function
Matlab and Scilab int16 behave differently :
int16() wraps,
while Matlab's mtlb_int16() saturates.int16() truncates the
fractional part, while Matlab's mtlb_int16() rounds to the
nearest integer.| x | int16(x) | mtlb_int16(x) |
|---|---|---|
| %nan | 0 | 0 |
| -%inf | -32768 | -32768 |
| -32770 | +32766 | -32768 |
| -32769 | +32767 | -32768 |
| -32768 | -32768 | -32768 |
| -32767 | -32767 | -32767 |
| -80.7 | -80 | -81 |
| -80.5 | -80 | -81 |
| -80.4 | -80 | -80 |
| 10.2 | 10 | 10 |
| 10.5 | 10 | 11 |
| 10.51 | 10 | 11 |
| 32767 | +32767 | 32767 |
| 32768 | -32768 | 32767 |
| 32769 | -32767 | 32767 |
| 32770 | -32766 | 32767 |
| %inf | +32767 | 32767 |
![]() |
The function |