www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/29/19:31:43

Message-ID: <37506CEA.7FA8@ns.sympatico.ca>
From: Klaas <klaas AT ns DOT sympatico DOT ca>
Organization: N/A
X-Mailer: Mozilla 3.04 (Win95; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: how to round fp-numbers correctly ?
References: <8710ed13 DOT 2481af58 AT aol DOT com>
Lines: 9
Date: Sat, 29 May 1999 19:40:42 -0300
NNTP-Posting-Host: 142.177.33.123
X-Trace: sapphire.mtt.net 928017963 142.177.33.123 (Sat, 29 May 1999 19:46:03 ADT)
NNTP-Posting-Date: Sat, 29 May 1999 19:46:03 ADT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

> where min is the lower bound integer number. If you don't have
> bounded numbers, then what you said is right, you need to treat
> positive and negative numbers separately. For example, a macro
> #define ROUND(x) ((x >= 0) ? (int) (x + 0.5) : (int) (x - 0.5))
> should do the trick.
> 

How about:
#define ROUND(x) ((x) + SGN(x)*0.5)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019