TRUNCATE IEEE754 FLOAT

Sign in to follow this  
Followers 0

About This File

Sometimes is necessary to truncate (remove the fraction) or round a floating point number that is outside the range of -32678 to +32767 - making it impossible to use a MOV to an integer to make the conversion.

This is a program I worte that shows how to perform a truncation directly on the floating point number by copyng the 32 bit pattern of the float and then determining which bits of the mantissa to keep and clearing all the rest. It includes three subroutines two of which show two different methods of truncating the float and a third which rounds the float to the nearest whole float.

An understanding of the IEEE-754 float format is helpful in understanding how this program works but its not necessary to use it.