Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Math expression evaluation error?
On Fri, 09 Jan 2015 13:40:42 -0800
jdh <dhenman@xxxxxxxxx> wrote:
> 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."
Thanks, that's just the sort of useful feedback on what people find
confusing that we need. I've adapted it into the appropriate section of
the manual with minor corrections.
diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo
index a620b73..5c334ce 100644
--- a/Doc/Zsh/arith.yo
+++ b/Doc/Zsh/arith.yo
@@ -233,6 +233,15 @@ necessary. In addition, if any operator which requires an integer
equivalents with assignment) is given a floating point argument, it will be
silently rounded down to the next integer.
+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 tt(6/8) is truncated,
+in this being rounded down to 0. The tt(FORCE_FLOAT) shell option can
+be used in scripts or functions where floating point evaluation is
+required throughout.
+
Scalar variables can hold integer or floating point values at different
times; there is no memory of the numeric type in this case.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author