Missing documentation of the integer range (declare -i)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing documentation of the integer range (declare -i)

dirk
Checked against:  GNU bash, Version 4.4.12(1)-release (x86_64-pc-linux-
gnu)

I carefully read the man page and find no definition of the defined
range of integer variables in bash.
see also:  `man bash |& grep -i integer`

Best Regards,

H.-Dirk Schmitt
Reply | Threaded
Open this post in threaded view
|

Re: Missing documentation of the integer range (declare -i)

Greg Wooledge
On Wed, Dec 06, 2017 at 03:35:51PM +0100, H.-Dirk Schmitt wrote:
> I carefully read the man page and find no definition of the defined
> range of integer variables in bash.

Bash uses signed 64-bit integers for arithmetic, since version 2.05b.
Before that, it was either 32-bit or platform-defined; I'm not sure
which.

(Also, don't use declare -i.  Please.  It's atrocious.)

wooledg:~$ echo $((2**63-1))
9223372036854775807
wooledg:~$ echo $((2**63))
-9223372036854775808

Reply | Threaded
Open this post in threaded view
|

Re: Missing documentation of the integer range (declare -i)

Chet Ramey
In reply to this post by dirk
On 12/6/17 7:35 AM, H.-Dirk Schmitt wrote:
> Checked against:  GNU bash, Version 4.4.12(1)-release (x86_64-pc-linux-
> gnu)
>
> I carefully read the man page and find no definition of the defined
> range of integer variables in bash.
> see also:  `man bash |& grep -i integer`

It's machine-dependent. The documentation guarantees only `fixed-width
integers', represented as intmax_t. That gives you the widest range
possible on the platform for which your binary was built.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/

Reply | Threaded
Open this post in threaded view
|

Re: Missing documentation of the integer range (declare -i)

Chet Ramey
In reply to this post by Greg Wooledge
On 12/6/17 7:53 AM, Greg Wooledge wrote:
> On Wed, Dec 06, 2017 at 03:35:51PM +0100, H.-Dirk Schmitt wrote:
>> I carefully read the man page and find no definition of the defined
>> range of integer variables in bash.
>
> Bash uses signed 64-bit integers for arithmetic, since version 2.05b.
> Before that, it was either 32-bit or platform-defined; I'm not sure
> which.

It's always been platform-dependent. It used to be `unsigned long', now
it's `intmax_t'.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/