summaryrefslogtreecommitdiff
path: root/rts/RtsUtils.c
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2010-04-21 16:23:36 +0000
committerIan Lynagh <igloo@earth.li>2010-04-21 16:23:36 +0000
commit81c95f7d9854521a568179bb19199299835b7a53 (patch)
tree148e2833ad3112356c87f0b9286032484d587181 /rts/RtsUtils.c
parent7dbc1d8f8fb650162e01f6eab8dabaf1f53c819d (diff)
downloadhaskell-81c95f7d9854521a568179bb19199299835b7a53.tar.gz
Use StgWord64 instead of ullong
This patch also fixes ullong_format_string (renamed to showStgWord64) so that it works with values outside the 32bit range (trac #3979), and simplifies the without-commas case.
Diffstat (limited to 'rts/RtsUtils.c')
-rw-r--r--rts/RtsUtils.c85
1 files changed, 67 insertions, 18 deletions
diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c
index 9021909dfa..dc11cb46ef 100644
--- a/rts/RtsUtils.c
+++ b/rts/RtsUtils.c
@@ -330,25 +330,74 @@ time_str(void)
-------------------------------------------------------------------------- */
char *
-ullong_format_string(ullong x, char *s, rtsBool with_commas)
+showStgWord64(StgWord64 x, char *s, rtsBool with_commas)
{
- if (x < (ullong)1000)
- sprintf(s, "%lu", (lnat)x);
- else if (x < (ullong)1000000)
- sprintf(s, (with_commas) ? "%lu,%3.3lu" : "%lu%3.3lu",
- (lnat)((x)/(ullong)1000),
- (lnat)((x)%(ullong)1000));
- else if (x < (ullong)1000000000)
- sprintf(s, (with_commas) ? "%lu,%3.3lu,%3.3lu" : "%lu%3.3lu%3.3lu",
- (lnat)((x)/(ullong)1000000),
- (lnat)((x)/(ullong)1000%(ullong)1000),
- (lnat)((x)%(ullong)1000));
- else
- sprintf(s, (with_commas) ? "%lu,%3.3lu,%3.3lu,%3.3lu" : "%lu%3.3lu%3.3lu%3.3lu",
- (lnat)((x)/(ullong)1000000000),
- (lnat)((x)/(ullong)1000000%(ullong)1000),
- (lnat)((x)/(ullong)1000%(ullong)1000),
- (lnat)((x)%(ullong)1000));
+ if (with_commas) {
+ if (x < (StgWord64)1e3)
+ sprintf(s, "%" FMT_Word64, (StgWord64)x);
+ else if (x < (StgWord64)1e6)
+ sprintf(s, "%" FMT_Word64 ",%03" FMT_Word64,
+ (StgWord64)(x / 1000),
+ (StgWord64)(x % 1000));
+ else if (x < (StgWord64)1e9)
+ sprintf(s, "%" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64,
+ (StgWord64)(x / 1e6),
+ (StgWord64)((x / 1000) % 1000),
+ (StgWord64)(x % 1000));
+ else if (x < (StgWord64)1e12)
+ sprintf(s, "%" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64,
+ (StgWord64)(x / (StgWord64)1e9),
+ (StgWord64)((x / (StgWord64)1e6) % 1000),
+ (StgWord64)((x / (StgWord64)1e3) % 1000),
+ (StgWord64)(x % 1000));
+ else if (x < (StgWord64)1e15)
+ sprintf(s, "%" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64,
+ (StgWord64)(x / (StgWord64)1e12),
+ (StgWord64)((x / (StgWord64)1e9) % 1000),
+ (StgWord64)((x / (StgWord64)1e6) % 1000),
+ (StgWord64)((x / (StgWord64)1e3) % 1000),
+ (StgWord64)(x % 1000));
+ else if (x < (StgWord64)1e18)
+ sprintf(s, "%" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64,
+ (StgWord64)(x / (StgWord64)1e15),
+ (StgWord64)((x / (StgWord64)1e12) % 1000),
+ (StgWord64)((x / (StgWord64)1e9) % 1000),
+ (StgWord64)((x / (StgWord64)1e6) % 1000),
+ (StgWord64)((x / (StgWord64)1e3) % 1000),
+ (StgWord64)(x % 1000));
+ else
+ sprintf(s, "%" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64
+ ",%03" FMT_Word64,
+ (StgWord64)(x / (StgWord64)1e18),
+ (StgWord64)((x / (StgWord64)1e15) % 1000),
+ (StgWord64)((x / (StgWord64)1e12) % 1000),
+ (StgWord64)((x / (StgWord64)1e9) % 1000),
+ (StgWord64)((x / (StgWord64)1e6) % 1000),
+ (StgWord64)((x / (StgWord64)1e3) % 1000),
+ (StgWord64)(x % 1000));
+ }
+ else {
+ sprintf(s, "%" FMT_Word64, x);
+ }
return s;
}