NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-mips/57680: printf("%.1f") shows wrong resultsonR3000mipseb



The following reply was made to PR port-mips/57680; it has been noted by GNATS.

From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
To: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
Cc: gnats-bugs%netbsd.org@localhost, tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: port-mips/57680: printf("%.1f") shows wrong resultsonR3000mipseb
Date: Sun, 5 Nov 2023 01:41:38 +0000

 > Date: Sun, 5 Nov 2023 03:05:04 +0900
 > From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
 > 
 > > > I doubt this problem was really compiler issue and
 > > > I wonder if it's okay to assume "FE_TONEAREST" is default
 > > > because FE_TOZERO works.
 > > 
 > > FE_TONEAREST is the correct default.  This has been the standard in
 > > IEEE 754 since 1985; essentially all hardware since then will
 > > implement it as the default, and essentially all numerical software
 > > that relies on any rounding mode will rely on that as the default.
 > 
 > Even in case that libm is not linked?
 
 Correct.  With or without libm, the default is _always_ FE_TONEAREST
 on any IEEE 754 system.  The only supported way to change this is via
 fesetround (or the nonstandard legacy fpsetround).
 
 > Anyway, I'm a bit disgusted because everyone complains
 > "investigate and fix actual problem rather than temprary workaround"
 > without MD analysis.
 
 Sorry, I don't know what the problem is here and I haven't had time to
 investigate myself.  It seems that this is a problem with some
 particular MIPS CPUs.
 
 Perhaps on these CPUs, the kernel is setting the default rounding mode
 wrong when it enters a new userland process.  You could test this by
 writing a program that just queries fegetround and prints the value:
 
 #include <fenv.h>
 #include <stdio.h>
 
 int
 main(void)
 {
 	printf("FE_TONEAREST = %d\n", (int)FE_TONEAREST);
 	printf("fegetround() = %d\n", (int)fegetround());
 	fflush(stdout);
 	return ferror(stdout);
 }
 
 Or, perhaps the rounding mode constants are wrong on this CPU somehow,
 and need translation in fegetround/fesetround.
 


Home | Main Index | Thread Index | Old Index