ThomasDickey / original-mawk

bug-reports for mawk (originally on GoogleCode)
http://invisible-island.net/mawk/mawk.html
17 stars 2 forks source link

can't convert 64 bits hex to decimal #37

Closed yimyom closed 1 year ago

yimyom commented 8 years ago

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.

jlp765 commented 8 years 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.

Solution:

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).

ThomasDickey commented 1 year ago

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
yimyom commented 1 year ago

7 years later :-) Wow! Thanks!

ThomasDickey commented 1 year ago

Actually less than five (see sizes.h)