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

Re: arithmetic anomaly



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