Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gdtoa Via enh at google dot com in tech-userlevel. ...



details:   https://anonhg.NetBSD.org/src/rev/f004ad0a8185
branches:  trunk
changeset: 1009069:f004ad0a8185
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 11 20:28:28 2020 +0000

description:
Via enh at google dot com in tech-userlevel. Fix handling of
EXT_FRAC{H,L}BITS (although we don't need to since we don't have them).

diffstat:

 lib/libc/gdtoa/hdtoa.c |  25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diffs (66 lines):

diff -r d0e407a89f21 -r f004ad0a8185 lib/libc/gdtoa/hdtoa.c
--- a/lib/libc/gdtoa/hdtoa.c    Sat Apr 11 17:52:01 2020 +0000
+++ b/lib/libc/gdtoa/hdtoa.c    Sat Apr 11 20:28:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hdtoa.c,v 1.9 2011/07/04 11:46:41 mrg Exp $    */
+/*     $NetBSD: hdtoa.c,v 1.10 2020/04/11 20:28:28 christos Exp $      */
 
 /*-
  * Copyright (c) 2004, 2005 David Schultz <das%FreeBSD.ORG@localhost>
@@ -30,7 +30,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.4 2007/01/03 04:57:58 das Exp $");
 #else
-__RCSID("$NetBSD: hdtoa.c,v 1.9 2011/07/04 11:46:41 mrg Exp $");
+__RCSID("$NetBSD: hdtoa.c,v 1.10 2020/04/11 20:28:28 christos Exp $");
 #endif
 
 #include <float.h>
@@ -310,23 +310,34 @@
         */
        for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
                *s = 0;
-       for (; s > s0 + sigfigs - (EXT_FRACLBITS / 4) - 1 && s > s0; s--) {
+       for (; s > s0 + sigfigs -
+           (EXT_FRACLBITS / 4) - 1 && s > s0; s--) {
                *s = u.extu_ext.ext_fracl & 0xf;
                u.extu_ext.ext_fracl >>= 4;
        }
 #ifdef EXT_FRACHMBITS
-       for (; s > s0; s--) {
+       for (; s > s0 + sigfigs - 
+           ((EXT_FRACLBITS + EXT_FRACHMBITS) / 4) - 1; s--) {
                *s = u.extu_ext.ext_frachm & 0xf;
                u.extu_ext.ext_frachm >>= 4;
        }
+#else
+#define EXT_FRACHMBITS 0
 #endif
+
 #ifdef EXT_FRACLMBITS
-       for (; s > s0; s--) {
+       for (; s > s0 + sigfigs -
+           ((EXT_FRACLBITS + EXT_FRACHMBITS + EXT_FRACLMBITS) / 4) - 1; s--) {
+
                *s = u.extu_ext.ext_fraclm & 0xf;
                u.extu_ext.ext_fraclm >>= 4;
        }
+#else
+#define EXT_FRACLMBITS 0
 #endif
-       for (; s > s0; s--) {
+
+       for (; s > s0 + sigfigs -
+           ((EXT_FRACLBITS + EXT_FRACHMBITS + EXT_FRACLMBITS + EXT_FRACHBITS) / 4) - 1; s--) {
                *s = u.extu_ext.ext_frach & 0xf;
                u.extu_ext.ext_frach >>= 4;
        }
@@ -337,7 +348,7 @@
         * (partial) nibble, which is dealt with by the next
         * statement.  We also tack on the implicit normalization bit.
         */
-       *s = u.extu_ext.ext_frach | (1U << ((LDBL_MANT_DIG - 1) % 4));
+       *s = (u.extu_ext.ext_frach | (1U << ((LDBL_MANT_DIG - 1) % 4))) 0xf;
 
        /* If ndigits < 0, we are expected to auto-size the precision. */
        if (ndigits < 0) {



Home | Main Index | Thread Index | Old Index