help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How How one reliably get is the maximum integer value


From: Tapani Tarvainen
Subject: Re: How How one reliably get is the maximum integer value
Date: Thu, 28 Jul 2022 15:22:14 +0300

On Thu, Jul 28, 2022 at 07:00:14AM -0400, Greg Wooledge (greg@wooledge.org) 
wrote:
> 
> > On Thu, Jul 28, 2022, 12:13 Budi <budikusasi@gmail.com> wrote:
> > > How can one reliably get is the maximum integer numeric value in one's
> > > bash currently installed as is ?
> 
> On Thu, Jul 28, 2022 at 12:24:56PM +0200, Alex fxmbsw7 Ratchev wrote:
> > look in the mails of last one two weeks, it came
> > sorry for not more
> 
> It was on the other mailing list, bug-bash, not here on help-bash.  Thread
> starting point:
> <https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00105.html>
> 
> Chet's answer:
> <https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00114.html>

For the sake of completeness, there are machines with a word length
that's not 16, 32 or 64 or even any power of two. I don't know if bash
runs in any such machine, or indeed if any such are actually still in
production use anywhere (probably not), but here's one way to get the
maximum integer in any case:

a=$( printf "%x" -1 )
MAXINT=$(( 0x$(( 0x${a::1} >> 1 ))${a:1} ))

Not seriously recommended for any use other than having fun with bash
features. :-)

-- 
Tapani Tarvainen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]