Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: arithmetic anomaly
- X-seq: zsh-users 26606
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: arithmetic anomaly
- Date: Fri, 26 Mar 2021 01:16:00 +0100
- Archived-at: <https://zsh.org/users/26606>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-03/91303-1616717760.288585%40Iyj2.F9RA.VD0P>
- In-reply-to: <0227b30d-4f09-2c8b-1248-557859d875ce@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <0227b30d-4f09-2c8b-1248-557859d875ce@eastlink.ca>
Ray Andrews wrote:
> printf "%.0f / %.0f \n" "$(( numerator ))" "$(( denominator ))"
Where you use %f, %d etc. the printf parameters are evaluated in math
context so there's no need to convert via ASCII decimal representation
with "$(( … ))". You can just do:
printf "%.0f / %.0f \n" numerator denominator
or even
printf "%.0f / %.0f \n" numerator 'level**level'
That feature is particular to zsh's printf. It doesn't really get you
much further with this particular script. Arbitrary precision (bignums)
might have been appropriate in the case of the shell rather than floats
but floats are what we have.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author