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

Math expression evaluation error?



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.

That is not true if the word "any" is true or a bug has crawled into the
numeric expression evaluator.  Or I read wrong..

Example on my system, zsh 5.0.7 (i686-pc-linux-gnu), I get the following
results for the shown example:

$ echo $(( 6+3/8. + 10 + 5/8. )) $(( 6+3/8 + 10 + 5/8. ))
                              17. 16.625

In the above case only the second term which contains a real number is
evaluated as real , the previous term is taken as integer and decimal
values are truncated (non-existent.   This same behavior is demonstrated
in zcalc.  Probably uses the same logic.

Though I understand why this happens (or think I do).  It could cause
someone a major mistake if they are unaware of this and rely on the outcome.

Regards

 Darel



Messages sorted by: Reverse Date, Date, Thread, Author