[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Can `declare -i` increase the performance of integer ari
From: |
Peng Yu |
Subject: |
Re: [Help-bash] Can `declare -i` increase the performance of integer arithmetic? |
Date: |
Thu, 8 Feb 2018 10:26:17 -0600 |
Is a variable always stored as a string whether `declare -i` is used?
It sounds like if `declare -i` is used on a variable, it is content
should be saved as an integer instead of a string as it is likely that
subsequent arithmetic operations will be performed on the variable. Is
it?
On Mon, Jan 22, 2018 at 8:28 AM, Chet Ramey <address@hidden> wrote:
> On 1/22/18 8:48 AM, Peng Yu wrote:
>>> No, it's not meant to improve performance.
>>
>> Then, what is the purpose of `declare -i`?
>
> The purpose is as documented.
>
> For assignment statements:
>
> "If the variable has its integer attribute set, then value
> is evaluated as an arithmetic expression even if the $((...)) expansion
> is not used (see Arithmetic Expansion below)."
>
> This has implications for how += is treated when applied to a variable
> with the integer attribute set.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/
--
Regards,
Peng
- Re: [Help-bash] Can `declare -i` increase the performance of integer arithmetic?,
Peng Yu <=