From: XXguille AT XXiies DOT XXes (Guillermo Rodriguez Garcia) Newsgroups: comp.os.msdos.djgpp Subject: Re: how to round fp-numbers correctly ? Date: Mon, 31 May 1999 09:52:14 GMT Organization: Telefonica Transmision de Datos Lines: 24 Message-ID: <3756b442.4342625@noticias.iies.es> References: <37504A52 DOT DA4C5283 AT gmx DOT de> NNTP-Posting-Host: iies233.iies.es Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Forte Agent 1.5/32.451 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com El día Sat, 29 May 1999 22:13:07 +0200, Christian Hofrichter escribió: >Another problem is the limited precision. Let's say some fp-operations >should return 100.0 but return 99.9999998 due to precision problems. If >I must compare this value (e.g in a loop) to define an end-condition I >need a comparing methode which says that 99.9999998 is equal to 100.0 >and aborts the loop. Is this possible ? Otherwise testing if the >variable is greater or equal to 100.0 would fail and the loop would be >continued. /* Assuming that you are using doubles, use a multiple of DBL_EPSILON. The factor should be similar to the absolute value of the numbers you are working with. There are other XXX_EPSILON constants defined for other data types */ /* comparisons should look like this */ if (fabs(value - 100.0) < (100.0 * DBL_EPSILON)) { ... } Regards, GUILLE ---- Guillermo Rodriguez Garcia XXguille AT XXiies DOT XXes (ya sabes :-)