zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: forcing float arithmetic.
Date: Wed, 24 Mar 2021 19:37:35 -0700	[thread overview]
Message-ID: <CAH+w=7b7KsHEAm0vf3VNQiG6X4zOqr6QXcjBy7iSjy70Yq10VQ@mail.gmail.com> (raw)
In-Reply-To: <0421525d-8304-6142-04bd-4f564ca043c0@eastlink.ca>

On Wed, Mar 24, 2021 at 6:45 PM Ray Andrews <rayandrews@eastlink.ca> 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.


  reply	other threads:[~2021-03-25  2:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 17:19 Ray Andrews
2021-03-24 17:56 ` Bart Schaefer
2021-03-24 21:51   ` Ray Andrews
2021-03-24 21:54     ` Roman Perepelitsa
2021-03-24 21:59       ` Bart Schaefer
2021-03-25  1:12         ` Ray Andrews
2021-03-25  1:36           ` Daniel Shahaf
2021-03-25  1:45             ` Ray Andrews
2021-03-25  2:37               ` Bart Schaefer [this message]
2021-03-25  3:22                 ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7b7KsHEAm0vf3VNQiG6X4zOqr6QXcjBy7iSjy70Yq10VQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).