diff options
author | Neil Booth <neil@daikokuya.co.uk> | 2007-10-06 07:29:25 +0000 |
---|---|---|
committer | Neil Booth <neil@daikokuya.co.uk> | 2007-10-06 07:29:25 +0000 |
commit | 92f7e8d92581e031beeee3dc6c170f5c2cc7ea18 (patch) | |
tree | 99185e555a93de1bec3be16529fcb6959069b8c8 /lib/Support/APFloat.cpp | |
parent | a11ef82207cd7ab8a2d39c946bf6dc34636f2904 (diff) |
Cleaner, more general exponent output.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42690 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APFloat.cpp')
-rw-r--r-- | lib/Support/APFloat.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index 2be9f7b0d7..ac2e5f2c27 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -252,32 +252,33 @@ namespace { return result; } - /* Write out a decimal exponent. */ + /* Write out an unsigned decimal integer. */ static char * - writeDecimalExponent (char *dst, int exponent) + writeUnsignedDecimal (char *dst, unsigned int n) { - assert (exponent >= -65536 && exponent <= 65535); + char buff[40], *p; - if (exponent < 0) { - *dst++ = '-'; - exponent = -exponent; - } + p = buff; + do + *p++ = '0' + n % 10; + while (n /= 10); - if (exponent == 0) { - *dst++ = '0'; - } else { - char buff[12], *p; + do + *dst++ = *--p; + while (p != buff); - p = buff; - while (exponent) { - *p++ = '0' + exponent % 10; - exponent /= 10; - } + return dst; + } - do - *dst++ = *--p; - while (p != buff); - } + /* Write out a signed decimal integer. */ + static char * + writeSignedDecimal (char *dst, int value) + { + if (value < 0) { + *dst++ = '-'; + dst = writeUnsignedDecimal(dst, -(unsigned) value); + } else + dst = writeUnsignedDecimal(dst, value); return dst; } @@ -1865,7 +1866,7 @@ APFloat::convertNormalToHexString(char *dst, unsigned int hexDigits, /* Finally output the exponent. */ *dst++ = upperCase ? 'P': 'p'; - return writeDecimalExponent (dst, exponent); + return writeSignedDecimal (dst, exponent); } // For good performance it is desirable for different APFloats |