File Exchange

image thumbnail


version 1.0.4 (13.2 KB) by Nick Higham
Round matrix elements to lower precision in MATLAB


Updated 29 Jun 2020

GitHub view license on GitHub

chop is a MATLAB function for rounding the elements of a matrix to a lower precision arithmetic with one of several forms of rounding. Its intended use is for simulating arithmetic of different precisions (less than double) with various rounding modes. The input to chop should be single precision or double precision and the output will have the same type: the lower precision numbers are stored within a higher precision type.

The arithmetic formats supported are

'b', 'bfloat16' - bfloat16,
'h', 'half', 'fp16' - IEEE half precision (the default),
's', 'single', 'fp32' - IEEE single precision,
'd', 'double', 'fp64' - IEEE double precision,
'c', 'custom' - custom format.

Cite As

Nicholas J. Higham and Srikara Pranesh (2019). chop (, GitHub. Retrieved March 22, 2019.

Comments and Ratings (1)



Minor fixes and documentation improvements.


Deleted old citation.


Changed citation.


Added co-author.

MATLAB Release Compatibility
Created with R2018b
Compatible with R2016a to any release
Platform Compatibility
Windows macOS Linux