This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: floating point output


After looking at the C99 standard, I have updated the fix for the cvt() static
routine of vfnprintf.cxx so that it respects the desired case and sign (even for
NaN).

Robin

Index: vfnprintf.cxx
===================================================================
RCS file: /usr/cvs/eCos/base/packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -C4 -r1.1 -r1.2
*** vfnprintf.cxx	8 Mar 2001 08:57:18 -0000	1.1
--- vfnprintf.cxx	10 Aug 2001 10:06:14 -0000	1.2
***************
*** 729,750 ****
  static int
  cvt(double number, int prec, int flags, char *signp, int fmtch, char *startp,
      char *endp)
  {
!         char *p, *t;
          double fract;
          int dotrim, expcnt, gformat;
          double integer, tmp;
-         Cyg_libm_ieee_double_shape_type ieeefp;
  
          dotrim = expcnt = gformat = 0;
-         ieeefp.value = number;
-         if ( ieeefp.number.sign ){  // this checks for <0.0 and -0.0
-                 number = -number;
-                 *signp = '-';
-         } else
-                 *signp = 0;
- 
          fract = modf(number, &integer);
  
          /* get an extra slot for rounding. */
          t = ++startp;
--- 729,753 ----
  static int
  cvt(double number, int prec, int flags, char *signp, int fmtch, char *startp,
      char *endp)
  {
!     Cyg_libm_ieee_double_shape_type ieeefp;
!     char *t = startp;
! 
!     ieeefp.value = number;
!     *signp = 0;
!     if ( ieeefp.number.sign ){  // this checks for <0.0 and -0.0
!         number = -number;
!         *signp = '-';
!     }
! 
!     if (finite(number)) {
!         char *p;
          double fract;
          int dotrim, expcnt, gformat;
          double integer, tmp;
  
          dotrim = expcnt = gformat = 0;
          fract = modf(number, &integer);
  
          /* get an extra slot for rounding. */
          t = ++startp;
***************
*** 911,919 ****
                          if (*t != '.')
                                  ++t;
                  }
          }
!         return (t - startp);
  } // cvt()
  
  #endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
  
--- 914,943 ----
                          if (*t != '.')
                                  ++t;
                  }
          }
!     } else {
! 	unsigned case_adj;
! 	switch (fmtch) {
! 	case 'f':
! 	case 'g':
! 	case 'e':
! 	    case_adj = 'a' - 'A';
! 	    break;
! 	default:
! 	    case_adj = 0;
! 	}
! 	if (isnan(number)) {
! 	    *t++ = 'N' + case_adj;
! 	    *t++ = 'A' + case_adj;
! 	    *t++ = 'N' + case_adj;
! 	} else { // infinite
! 	    *t++ = 'I' + case_adj;
! 	    *t++ = 'N' + case_adj;
! 	    *t++ = 'F' + case_adj;
! 	}
!     }
!     return (t - startp);
  } // cvt()
  
  #endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]