2014-07-25 13:10 GMT+02:00 Jim Michaels <[email protected]>:
> #include <stdio.h>
> #include <_mingw.h>
> int main(void) {
> __int128 i=170141183460469231731687303715884105727LLL;
> unsigned __int128 u=340282366920938463463374607431768211455ULLL;
> //printf("i=%I128d\n", i);
> printf("%*d", 128/8, i);
> printf(" 170141183460469231731687303715884105727LLL\n");
>
> //printf("u=%I128u\n", u);
> printf("%*u", 128/8, u);
> printf("%lu", u);
> printf("%llu", u);
> printf("%lllu", u);
> printf("%I128u", u);
> printf(" 340282366920938463463374607431768211455ULLL\n");
> return 0;
> }
> /*
>
> __int128.cpp: In function 'int main()':
> __int128.cpp:4:16: error: unable to find numeric literal operator
> 'operator""LLL'
> __int128 i=170141183460469231731687303715884105727LLL;
> ^
> __int128.cpp:4:16: note: use -std=gnu++11 or -fext-numeric-literals to
> enable more built-in suffixes
> __int128.cpp:5:25: error: unable to find numeric literal operator
> 'operator""ULLL'
> unsigned __int128 u=340282366920938463463374607431768211455ULLL;
> ^
> __int128.cpp:5:25: note: use -std=gnu++11 or -fext-numeric-literals to
> enable more built-in suffixes
> __int128.cpp:7:24: warning: format '%d' expects argument of type 'int',
> but argument 3 has type '__int128' [-Wformat=]
> printf("%*d", 128/8, i);
> ^
> __int128.cpp:11:24: warning: format '%u' expects argument of type
> 'unsigned int', but argument 3 has type '__int128 unsigned' [-Wformat=]
> printf("%*u", 128/8, u);
> ^
> __int128.cpp:12:17: warning: format '%lu' expects argument of type 'long
> unsigned int', but argument 2 has type '__int128 unsigned' [-Wformat=]
> printf("%lu", u);
> ^
> __int128.cpp:13:18: warning: unknown conversion type character 'l' in
> format [-Wformat=]
> printf("%llu", u);
> ^
> __int128.cpp:13:18: warning: too many arguments for format
> [-Wformat-extra-args]
> __int128.cpp:14:19: warning: unknown conversion type character 'l' in
> format [-Wformat=]
> printf("%lllu", u);
> ^
> __int128.cpp:14:19: warning: too many arguments for format
> [-Wformat-extra-args]
> __int128.cpp:15:20: warning: unknown conversion type character '1' in
> format [-Wformat=]
> printf("%I128u", u);
> ^
> __int128.cpp:15:20: warning: too many arguments for format
> [-Wformat-extra-args]
>
> Fri 07/25/2014 4:07:36.01|d:\prj\test\mingw-w64\__int128|>call
> beepifexists.cmd __int128.exe
> EXISTS: __int128.exe
> -----failure-----
>
The fact that the compiler has a type does not mean the C library can
handle it.
This stackoverflow question
<http://stackoverflow.com/questions/11656241/how-to-print-uint128-t-number-using-gcc>
has a link <https://gist.github.com/zed/7f7e7451b60aff301fe0> to the
following code you can try:
#define P(n) do { \
print_hex(n); \
print_uint128(n); \
print(n); \
} while(0)
typedef __uint128_t uint128_t;
int print_hex(uint128_t n) {
uint64_t lo = n;
uint64_t hi = (n >> 64);
if (hi) {
printf("%" PRIX64, hi);
return printf("%016" PRIX64 "\n", lo);
}
return printf("%" PRIX64 "\n", lo);
}
int print(uint128_t n) {
if (n == 0) return printf("0\n");
uint64_t factor = 10000000000000; // 3*13 == 39: 2**128 < 10**39
const int size = 3;
uint64_t parts[size];
uint64_t *p = parts + size; // start at the end
while (p != parts) {
*--p = n % factor; // get last part
n /= factor; // drop it
}
for (p = parts; p != &parts[size]; ++p)
if (*p) {
printf("%" PRIu64, *p);
break; // found nonzero part
}
for ( ++p; p != &parts[size]; ++p)
printf("%013" PRIu64, *p);
return printf("\n");
}
int
print_uint128(uint128_t n) {
if (n == 0) return printf("0\n");
char str[40] = {0}; // log10(1 << 128) + '\0'
char *s = str + sizeof(str) - 1; // start at the end
while (n != 0) {
if (s == str) return -1; // never happens
*--s = "0123456789"[n % 10]; // save last digit
n /= 10; // drop it
}
return printf("%s\n", s);
}
Cheers, and please learn to google first. These are all top answers when
searching for keywords in your question.
Ruben
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public