Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: integer or float?
On Thu, Oct 2, 2025, at 9:10 AM, Ray Andrews wrote:
> However the above:
>
> % unsetopt FORCE_FLOAT
> % echo $((1.0))
> 1.
>
> ... really does seem like a mistake:
It's not a mistake.
> % setopt forcefloat; echo $((1.0))
> 1.
>
> % unsetopt forcefloat; echo $((1.0))
> 1.
>
> % unsetopt forcefloat; echo $((1))
> 1
>
> % setopt forcefloat; echo $((1))
> 1.
The third expression has an integer value and is displayed as such.
The other three have floating point values (due to the use of a
floating-point literal or FORCE_FLOAT) and are displayed as such.
> contrast the uniform an correct output here:
>
> % setopt forcefloat; echo $((.5))
> 0.5
>
> % unsetopt forcefloat; echo $((.5))
> 0.5
>
> % setopt forcefloat; echo $((0.5))
> 0.5
>
> % unsetopt forcefloat; echo $((0.5))
> 0.5
All four of these expressions have floating-point values and are
displayed as such. There is no inconsistency here.
> ... note that above zsh actually 'fixes it for you': '.5' becomes
> '0.5'. So we have rigor with leading zeros but not trailing zeros.
Please stop using terms like "rigor" and "correct" to express your
personal aesthetic preferences.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author