diff options
Diffstat (limited to 'src/stdlib/int64.c')
| -rw-r--r-- | src/stdlib/int64.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/stdlib/int64.c b/src/stdlib/int64.c index 754ac619..131d77ab 100644 --- a/src/stdlib/int64.c +++ b/src/stdlib/int64.c @@ -1,3 +1,19 @@ #define INTX_C_H__INT_BITS 64 #include "intX.c.h" #undef INTX_C_H__INT_BITS + +public +int Int64$print(FILE *f, int64_t n) { + char buf[21] = {[20] = 0}; // Big enough for INT64_MIN + '\0' + char *p = &buf[19]; + bool negative = n < 0; + + do { + *(p--) = '0' + (n % 10); + n /= 10; + } while (n > 0); + + if (negative) *(p--) = '-'; + + return fwrite(p + 1, sizeof(char), (size_t)(&buf[19] - p), f); +} |
