Browse Prior Art Database

A Method for Implementing Integer Round without Floating Comparisons

IP.com Disclosure Number: IPCOM000110488D
Original Publication Date: 1992-Nov-01
Included in the Prior Art Database: 2005-Mar-25
Document File: 1 page(s) / 50K

Publishing Venue

IBM

Related People

Alpern, B: AUTHOR [+3]

Abstract

Disclosed is a technique for implementing integer round in the floating point unit, without floating point comparisons. The method described works for machines running IEEE floating point round to nearest mode.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 85% of the total text.

A Method for Implementing Integer Round without Floating Comparisons

      Disclosed is a technique for implementing integer round in the
floating point unit, without floating point comparisons.  The method
described works for machines running IEEE floating point round to
nearest mode.

      The IEEE floating point standard specifies different rounding
modes.  These differ on how a number b between two consecutive
representable numbers a and c is handled.  In Round-toNearest (R2N)
mode, b become whichever of a or c that it is closer to.  If b
is exactly midway between a and c, b becomes whichever of a or c that
has a 0 as its last bit.

      Consider a programming construct ROUND(x) that returns the
nearest (floating-point) whole number to x for x in a given range
(say, -232 to 232).  If x is exactly midway between two consecutive
whole numbers, ROUND(x) returns the larger of these.

      In R2N mode, ROUND can almost be implemented as follows.
First, add MAGIC to x, where MAGIC is 2.052 + 2.051 + 1.  Then,
subtract MAGIC.  This works all floating point numbers in the range
-251 - 1 to 251 - 1, except those of the form 2.0 x N
- 0.5 where N is a whole number.  Such numbers get rounded to 2.0 x
N - 1.0 rather than to N.

      This invention is a program for implementing ROUND in R2N mode.
Similar techniques can be used to implement other rounding and
truncation functions.  The program works for all x in the range -251
- 1 to 251 - 1.  The pr...