Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
forcing float arithmetic.
- X-seq: zsh-users 26590
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: forcing float arithmetic.
- Date: Wed, 24 Mar 2021 10:19:47 -0700
- Archived-at: <https://zsh.org/users/26590>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-03/f09863a2-0af9-dbff-08b9-6f595cd7e164%40eastlink.ca>
- List-id: <zsh-users.zsh.org>
#integer nn=4
typeset -F nn=4
typeset -F aa=
(( aa = ((2 * nn) - 1) / (nn**2) ))
echo $aa
If 'nn' is declared as an integer the above echos zero but if as a float
the answer is correct. But nn will never actually be other than an
integer so I don't like to declare it as a float. Am I not expecting
successful arithmetic even with the integer? I know you can force the
issue with:
(( aa = ((2 * nn) - 1) / (nn**2.0) ))
... but I wonder why that's needed. Why are answers dumbed down like
that? It's clearly a design decision but it seems to me unnatural. If
'aa' was an integer too I understand the result would have to be rounded
down to zero, but since aa is a float, shouldn't all arithmetic
automatically produce floating point results?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author