Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Dave Korn" To: Subject: RE: SV: Bug in printf ? Date: Thu, 30 Jun 2005 17:48:04 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00B3_01C57D9B.DE110F30" In-Reply-To: <42C41685.5FE33AEA@dessent.net> Message-ID: ------=_NextPart_000_00B3_01C57D9B.DE110F30 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit ----Original Message---- >From: Brian Dessent >Sent: 30 June 2005 16:58 > Dave Korn wrote: > >> Absolutely, there's a rounding error of some sort. Compare the >> difference when compiling the testcase with -mno-cygwin (i.e. using >> mingw maths lib): > > Isn't this just a case of the Cygwin math library choosing "round to > even" and the MSVCRT/mingw library choosing "0.5 always rounds up"? No, I really don't think that's the case, in fact I reckon they both default to the same roundingmode, and the discrepancy remains the same in any rounding mode. Have a go with the attached version of the testcase, which allows you to choose any rounding mode you like at runtime: just pass a hex constant from the set (0, 0x400, 0x800, 0xc00) on the command line. cheers, DaveK -- Can't think of a witty .sigline today.... ------=_NextPart_000_00B3_01C57D9B.DE110F30 Content-Type: text/plain; name="aa2.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="aa2.c" #include #include #ifdef __MINGW32__ #include #endif #ifndef __MINGW32__ #define FE_TONEAREST 0x0000 #define FE_DOWNWARD 0x0400 #define FE_UPWARD 0x0800 #define FE_TOWARDZERO 0x0c00 /* 7.6.3.2 The fesetround function establishes the rounding direction represented by its argument round. If the argument is not equal to the value of a rounding direction macro, the rounding direction is not changed. */ int fesetround (int mode) { unsigned short _cw; if ((mode & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)) != 0) return -1; __asm__ volatile ("fnstcw %0;": "=m" (_cw)); _cw &= ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO); _cw |= mode; __asm__ volatile ("fldcw %0;" : : "m" (_cw)); return 0; } /* 7.6.3.1 The fegetround function returns the value of the rounding direction macro representing the current rounding direction. */ int fegetround (void) { unsigned short _cw; __asm__ ("fnstcw %0;" : "=m" (_cw)); return _cw & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO); } #endif int main(int argc, const char **argv) { if (argc >= 2) { int nrm, n; n = sscanf (argv[1], "%i", &nrm); if (n == 1) switch (nrm) { case 0: case 0x400: case 0x800: case 0xc00: fesetround (nrm); } } printf ("Rmode $%08x\n", fegetround ()); printf("%0.2f\n", 0.105); printf("%0.2f\n", 0.115); printf("%0.2f\n", 0.125); printf("%0.2f\n", 0.135); return 0; } ------=_NextPart_000_00B3_01C57D9B.DE110F30 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ------=_NextPart_000_00B3_01C57D9B.DE110F30--