Closed yimyom closed 1 year ago
This issue is raised many times (but not the solution to it).
It is not a bug per sae.
The printf types (eg %d in this instance) defines the type of the variable being parsed. So for the C language which is the language used to compiled mawk, that means the input is limited to a C integer.
So no, %d does NOT mean display any arbitrary signed decimal integer, but display any integer up to the MAX integer size.
use %.0f for integers and if you know the precision of your real numbers, specify the precision, eg %.20f.
Why does gawk printf %d give the answer I expect? Because gawk identifies that the number is bigger than Max_Int and uses %f to display it (ie, it gives you what you want, NOT WHAT YOU ASKED FOR).
current mawk handles 64-bit integers on 64-bit platforms, shown in the version message:
mawk 1.3.4 20230322
Copyright 2008-2022,2023, Thomas E. Dickey
Copyright 1991-1996,2014, Michael D. Brennan
random-funcs: srandom/random
regex-funcs: internal
compiled limits:
sprintf buffer 8192
maximum-integer 9223372036854775808
7 years later :-) Wow! Thanks!
Actually less than five (see sizes.h)
it seems mawk is still limited to 32 bits integer and therefore conversion of a 64 bits hexadecimal string will be blocked at FFFFFFFF, that is 32 bits only. printf("%d", "0x" "1FFFFFFFF") won't pass over the 32 bits limit.