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 results on R3000 mipseb



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

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: port-mips/57680: printf("%.1f") shows wrong results on R3000
 mipseb
Date: Fri, 3 Nov 2023 10:32:18 +0000 (UTC)

 On Fri, 3 Nov 2023, Izumi Tsutsui wrote:
 
 > It looks something wrong in libc.so.12.213 from NetBSD 9.3.
 > The same binary with libc.so.12.207 from NetBSD 8.2 works as expected.
 >
 > ---
 > # file ./a.out
 > ./a.out: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), dynamically linked, interpreter /usr/libexec/ld.elf_so, for NetBSD 9.3, not stripped
 > # file /lib/libc.so.12.213
 > /lib/libc.so.12.213: ELF 32-bit MSB shared object, MIPS, MIPS-I version 1 (SYSV), dynamically linked, for NetBSD 9.3, not stripped
 > # ./a.out
 > 300.0
 > 314
 > ?00.0
 > 1570
 > # chroot .
 > # file /lib/libc.so.12.207
 > /lib/libc.so.12.207: ELF 32-bit MSB shared object, MIPS, MIPS-I version 1 (SYSV), dynamically linked, for NetBSD 8.2, not stripped
 > # ./a.out
 > 314.2
 > 314
 > 1570.8
 > 1570
 > #
 >
 > ---
 >
 
 Can you show the output of this program? (Instructions in source)
 
 ```
 /**
   * Little-Endian 32-bit:
   * cc -I/usr/src/lib/libc/gdtoa/ -I/usr/src/lib/libc/arch/i386/gdtoa/ \
   *   -DDEBUG -DHonor_FLT_ROUNDS -DNO_LONG_LONG -o m \
   *   m.c /usr/src/lib/libc/gdtoa/dtoa.c /usr/src/lib/libc/gdtoa/dmisc.c
   *
   * Big-Endian 32-bit:
   * cc -I/usr/src/lib/libc/gdtoa/ -I/usr/src/lib/libc/arch/mips/gdtoa/ \
   *   -DDEBUG -DHonor_FLT_ROUNDS -DNO_LONG_LONG -o m \
   *   m.c /usr/src/lib/libc/gdtoa/dtoa.c /usr/src/lib/libc/gdtoa/dmisc.c
   */
 
 #include <stdio.h>
 
 char* __dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve);
 
 static void
 pr_f(char* s, int pt, int neg)
 {
  	if (s == NULL)
  		return;
  	if (pt < 0 || pt == 9999)	/* XXX: unhandled */
  		return;
          printf("%s", neg ? "-" : "");
  	printf("%.*s.", pt, s);
  	printf("%.1s\n", s + pt);
 }
 
 int
 main(int argc, char *argv[])
 {
  	int pt, neg;
  	char* p, *s;
 
  	union {
  		unsigned int i;
          	float f;
  	} u;
 
          u.f = 3.14159;
  	s = __dtoa(u.f, 3, 6, &pt, &neg, NULL);
  	pr_f(s, pt, neg);
          printf("%08X\n", u.i);
 
  	u.f = u.f * 100;
  	s = __dtoa(u.f, 3, 6, &pt, &neg, NULL);
  	pr_f(s, pt, neg);
          printf("%08X\n", u.i);
 
          u.f = u.f * 5;
  	s = __dtoa(u.f, 3, 6, &pt, &neg, NULL);
  	pr_f(s, pt, neg);
          printf("%08X\n", u.i);
 }
 ```
 
 -RVP
 


Home | Main Index | Thread Index | Old Index