Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: forcing float arithmetic.



On Wed, Mar 24, 2021 at 6:45 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> I'd think of it as polite.  Just now I'm doing this:
>
>      (( divided = sum * 1.0 / level ))
>
> ... and it really does seem belabored.

Doc, Arithmetic Evaluation section:

Users should beware that, in common with many other programming
languages but not software designed for calculation, the evaluation of
an expression in zsh is taken a term at a time and promotion of integers
to floating point does not occur in terms only containing integers.  A
typical result of this is that a division such as 6/8 is truncated, in
this being rounded towards 0.  The FORCE_FLOAT shell option can be used
in scripts or functions where floating point evaluation is required
throughout.




Messages sorted by: Reverse Date, Date, Thread, Author