bug-bash
[Top][All Lists]
Advanced

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

Re: [the result of $[23**15] is wrong]


From: Greg Wooledge
Subject: Re: [the result of $[23**15] is wrong]
Date: Mon, 11 Jul 2022 11:20:05 -0400

On Mon, Jul 11, 2022 at 10:14:12PM +0800, root@ROCKY8-5-WL.localdomain wrote:
>       [Detailed description of the problem, suggestion, or complaint.]
> in bash the result of $[23**15] is wrong
> for example output
> [root@ROCKY8-5-02 ~]#echo $[23**15]
> 8380818432457522983
> [root@ROCKY8-5-02 ~]#echo "23^15" | bc
> 266635235464391245607

First of all, the $[ ] syntax has been deprecated for two decades.
You should be using $(( )) instead.

Second, you've overflowed the variable type that bash is using on your
platform (most likely a 64-bit signed integer type).

unicorn:~$ bc -l
[...]
2^63
9223372036854775808
23^15
266635235464391245607

On almost all modern platforms, bash uses a 64-bit signed integer type
for its arithmetic.  The value you're trying to compute here is larger
than that type can hold.



reply via email to

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