[llvm-commits] [llvm] r42690 - /llvm/trunk/lib/Support/APFloat.cpp
Neil Booth
neil at daikokuya.co.uk
Sat Oct 6 00:29:25 PDT 2007
Author: neil
Date: Sat Oct 6 02:29:25 2007
New Revision: 42690
URL: http://llvm.org/viewvc/llvm-project?rev=42690&view=rev
Log:
Cleaner, more general exponent output.
Modified:
llvm/trunk/lib/Support/APFloat.cpp
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=42690&r1=42689&r2=42690&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Sat Oct 6 02:29:25 2007
@@ -252,32 +252,33 @@
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;
- }
-
- if (exponent == 0) {
- *dst++ = '0';
- } else {
- char buff[12], *p;
+ p = buff;
+ do
+ *p++ = '0' + n % 10;
+ while (n /= 10);
+
+ 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 @@
/* 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
More information about the llvm-commits
mailing list