zsh-workers
 help / color / mirror / code / Atom feed
From: jdh <dhenman@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Math expression evaluation error?
Date: Fri, 09 Jan 2015 13:40:42 -0800	[thread overview]
Message-ID: <54B04ADA.9050102@gmail.com> (raw)
In-Reply-To: <20150109201552.1304eafe@ntlworld.com>

Thanks for the detailed explanation.   I suggest that the an additional 
line be added to the manual, which would say something like:

"   Caution:  The evaluation of an expression is taken a term at a time 
and if there are mixed terms , say integer only and  float terms , the 
integer only ones will not be promoted to real values and the result of 
the whole expression would be an error to common standards. One can use 
the -f option or the  FORCE_FLOAT environment variable to change this 
behavior."

I apologize if this is in the manual already.

Regards.

On 2015年01月09日 12:15, Peter Stephenson wrote:
> On Fri, 09 Jan 2015 11:46:44 -0800
> jdh <dhenman@gmail.com> wrote:
>> I believe I read that math expression evaluation will convert all
>> calculations in an expression if "any" value in that expression is a
>> real value.
> This isn't the case and wherever this came from needs correcting.
> Please instead read the documentation under ARITHMETIC EVALUATION in the
> zshmisc manual for what actually happens and let us if know if you think
> that is inadequate.  The actually phrasing is "Promotion of integer to
> floating point values is performed where necessary".  It also refers
> above that to C --- there's an underlying assumption here that the user
> has some idea of the operation of C-like languages, which might of
> course not be the case.  "Where necessary" is in general where an
> operator has a floating point number as one argument and an integer as
> another; a C programmer would recognise the use of the word "promotion"
> as implying this, a general user probably not.  So the wording could
> probably be improved.  Brief and to the point suggestions on this from
> anyone are welcome (long rambles on why anyone doesn't understand it
> may be invigorating for the rambler but are less useful to us as
> developers :-)).
>
> See also the following shell option:
>
> FORCE_FLOAT
>         Constants in arithmetic evaluation will be treated  as  floating
>         point  even without the use of a decimal point.  Integers in any
>         base will be converted.
>
> This is most useful in zcalc, which actually has an option for this.
>
>         If the option `-f' is set, all numbers are treated  as  floating
>         point,  hence for example the expression `3/4' evaluates to 0.75
>         rather than 0.  Options must appear in separate words.
>
> pws


  reply	other threads:[~2015-01-09 21:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-09 19:46 jdh
2015-01-09 20:15 ` Peter Stephenson
2015-01-09 21:40   ` jdh [this message]
2015-01-09 22:19     ` Ray Andrews
2015-01-09 23:06       ` Lawrence Velázquez
2015-01-09 23:52         ` Ray Andrews
2015-01-10  0:25           ` Bart Schaefer
2015-01-10  7:27             ` Ray Andrews
2015-01-10 16:53               ` Bart Schaefer
2015-01-10 18:48                 ` Ray Andrews
2015-01-10 19:14                   ` Bart Schaefer
2015-01-10 22:21                     ` Ray Andrews
2015-01-11  1:51                       ` Bart Schaefer
2015-01-11  5:10                         ` Ray Andrews
2015-01-12  9:17                           ` Vincent Lefevre
2015-01-12 16:18                             ` ZyX
2015-01-13 16:00                               ` Vincent Lefevre
2015-01-13 23:03                                 ` ZyX
2015-01-14 14:47                                   ` Vincent Lefevre
2015-01-14 21:37                                     ` ZyX
2015-01-15 13:34                                       ` Vincent Lefevre
2015-01-15 13:41                                         ` Vincent Lefevre
2015-01-15 18:32                                         ` ZyX
2015-01-15 21:57                                           ` Bart Schaefer
2015-01-09 22:40     ` Peter Stephenson
2015-01-12 10:55       ` Peter Stephenson
2015-01-14 15:02       ` Vincent Lefevre
2015-01-14 15:38         ` Peter Stephenson
2015-01-15 14:58           ` Peter Stephenson

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=54B04ADA.9050102@gmail.com \
    --to=dhenman@gmail.com \
    --cc=zsh-workers@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).