From ... From: Erik Naggum Subject: Re: Gnu Common Lisp HELP! Date: 1996/01/12 Message-ID: <19960112T003832Z@arcana.naggum.no>#1/1 X-Deja-AN: 135135770 references: <30F51D2D.C84@ling.umu.se> <19960111T202920Z@arcana.naggum.no> organization: Naggum Software; +47 2295 0313 newsgroups: comp.lang.lisp a clarification of my previous article may be necessary if you're unfamiliar with rounding functions. | note that the Common Lisp `round' function rounds to even integers. rounding functions differ in behavior for the value N + 1/2. some round up to N + 1, some round down to N, some round to the nearest even integer, some round towards zero (down for positive values, up for negative values), some round towards infinity (the opposite). for all other values, these functions agree that N + F, for -1/2 < F < 1/2, rounds to N. here's a breakdown that might illustrate this mess: up down even zero infinity -4.7 -5 -5 -5 -5 -5 -4.5 -4 -5 -4 -4 -5 -4.2 -4 -4 -4 -4 -4 -3.5 -3 -4 -4 -3 -4 3.5 4 3 4 3 4 4.2 4 4 4 4 4 4.5 5 4 4 4 5 4.7 5 5 5 5 5 I hope this forestalls any confusion. note that when computing values with floating point representation, losing bits of precision requires rounding. very frequently (if not exclusively), one loses exactly one bit of precision, and when this happens, the smallest accumulated rounding error is obtained by rounding to even. Common Lisp offers a number of other float-or-rational-to-integer conversion functions, as well: floor (truncate towards negative infinity), ceiling (truncate towards positive infinity), and truncate (towards zero). # -- the problem with this "information superhighway" is mainly that if you ask people to go play in it, they don't even understand when they get run over.