security/sandbox/chromium/base/third_party/dmg_fp/g_fmt.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/third_party/dmg_fp/g_fmt.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +/****************************************************************
     1.5 + *
     1.6 + * The author of this software is David M. Gay.
     1.7 + *
     1.8 + * Copyright (c) 1991, 1996 by Lucent Technologies.
     1.9 + *
    1.10 + * Permission to use, copy, modify, and distribute this software for any
    1.11 + * purpose without fee is hereby granted, provided that this entire notice
    1.12 + * is included in all copies of any software which is or includes a copy
    1.13 + * or modification of this software and in all copies of the supporting
    1.14 + * documentation for such software.
    1.15 + *
    1.16 + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
    1.17 + * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
    1.18 + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
    1.19 + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
    1.20 + *
    1.21 + ***************************************************************/
    1.22 +
    1.23 +/* g_fmt(buf,x) stores the closest decimal approximation to x in buf;
    1.24 + * it suffices to declare buf
    1.25 + *	char buf[32];
    1.26 + */
    1.27 +
    1.28 +#include "dmg_fp.h"
    1.29 +
    1.30 +namespace dmg_fp {
    1.31 +
    1.32 + char *
    1.33 +g_fmt(register char *b, double x)
    1.34 +{
    1.35 +	register int i, k;
    1.36 +	register char *s;
    1.37 +	int decpt, j, sign;
    1.38 +	char *b0, *s0, *se;
    1.39 +
    1.40 +	b0 = b;
    1.41 +#ifdef IGNORE_ZERO_SIGN
    1.42 +	if (!x) {
    1.43 +		*b++ = '0';
    1.44 +		*b = 0;
    1.45 +		goto done;
    1.46 +		}
    1.47 +#endif
    1.48 +	s = s0 = dtoa(x, 0, 0, &decpt, &sign, &se);
    1.49 +	if (sign)
    1.50 +		*b++ = '-';
    1.51 +	if (decpt == 9999) /* Infinity or Nan */ {
    1.52 +		while((*b++ = *s++)) {}
    1.53 +		goto done0;
    1.54 +		}
    1.55 +	if (decpt <= -4 || decpt > se - s + 5) {
    1.56 +		*b++ = *s++;
    1.57 +		if (*s) {
    1.58 +			*b++ = '.';
    1.59 +			while((*b = *s++))
    1.60 +				b++;
    1.61 +			}
    1.62 +		*b++ = 'e';
    1.63 +		/* sprintf(b, "%+.2d", decpt - 1); */
    1.64 +		if (--decpt < 0) {
    1.65 +			*b++ = '-';
    1.66 +			decpt = -decpt;
    1.67 +			}
    1.68 +		else
    1.69 +			*b++ = '+';
    1.70 +		for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10) {}
    1.71 +		for(;;) {
    1.72 +			i = decpt / k;
    1.73 +			*b++ = i + '0';
    1.74 +			if (--j <= 0)
    1.75 +				break;
    1.76 +			decpt -= i*k;
    1.77 +			decpt *= 10;
    1.78 +			}
    1.79 +		*b = 0;
    1.80 +		}
    1.81 +	else if (decpt <= 0) {
    1.82 +		*b++ = '.';
    1.83 +		for(; decpt < 0; decpt++)
    1.84 +			*b++ = '0';
    1.85 +		while((*b++ = *s++)) {}
    1.86 +		}
    1.87 +	else {
    1.88 +		while((*b = *s++)) {
    1.89 +			b++;
    1.90 +			if (--decpt == 0 && *s)
    1.91 +				*b++ = '.';
    1.92 +			}
    1.93 +		for(; decpt > 0; decpt--)
    1.94 +			*b++ = '0';
    1.95 +		*b = 0;
    1.96 +		}
    1.97 + done0:
    1.98 +	freedtoa(s0);
    1.99 +#ifdef IGNORE_ZERO_SIGN
   1.100 + done:
   1.101 +#endif
   1.102 +	return b0;
   1.103 +	}
   1.104 +
   1.105 +}  // namespace dmg_fp

mercurial