From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1546 invoked by alias); 12 Jan 2015 10:55:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34253 Received: (qmail 25844 invoked from network); 12 Jan 2015 10:55:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-df-54b3a8372e8f Date: Mon, 12 Jan 2015 10:55:48 +0000 From: Peter Stephenson To: Peter Stephenson , zsh-workers@zsh.org Subject: Re: Math expression evaluation error? Message-id: <20150112105548.4f70173a@pwslap01u.europe.root.pri> In-reply-to: <20150109224034.294d4fd6@ntlworld.com> References: <54B03024.1030309@gmail.com> <20150109201552.1304eafe@ntlworld.com> <54B04ADA.9050102@gmail.com> <20150109224034.294d4fd6@ntlworld.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHLMWRmVeSWpSXmKPExsVy+t/xy7rmKzaHGFx8x2bRe+QGi8XB5odM DkweVyduY/JYdfADUwBTFJdNSmpOZllqkb5dAlfGmQPN7AUHBSoWX1/E2MD4greLkYNDQsBE 4u1/2y5GTiBTTOLCvfVsXYxcHEICSxkltrf2M4MkhAR6mCRa3idAJLYxSjTvfsgEkmARUJVo +7CFDcRmEzCUmLppNiOILSLgLrHj1A9WEFtYQE9i8/suFpBlvAL2EtsORICEOQWMJWZcncYC MXMqo8TtRwvBZvIL6Etc/fuJCeIie4mZV86AzeQVEJT4MfkeC4jNLKAlsXlbEyuELS+xec1b qEPVJW7c3c0+gVFoFpKWWUhaZiFpWcDIvIpRNLU0uaA4KT3XUK84Mbe4NC9dLzk/dxMjJIy/ 7GBcfMzqEKMAB6MSD+8Emc0hQqyJZcWVuYcYJTiYlUR4XcuAQrwpiZVVqUX58UWlOanFhxiZ ODilGhhd3t7btNH0qwij/gIlJun4TyeEOILbneql5L/JzPhx6ezm9LNsLK3zvwVIvAwyWugQ fOf70tupgvdEQ1ofttddkn5jUPtQputSmjjbCvF3DfdWz5iT9LeHd11ElXXQoW/nS9KmvbZ4 XFd7MLHO+tQUlkMJcto3CzzeyocKaZ/kMrTdebeV75ASS3FGoqEWc1FxIgCtTcF+QQIAAA== On Fri, 9 Jan 2015 22:40:34 +0000 Peter Stephenson wrote: > +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. Before this drifts out of my mind, here's a similar warning for zcalc. Assuming anybody actually bothers to read the documentation... diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 5043243..00ede52 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3227,8 +3227,18 @@ A reasonably powerful calculator based on zsh's arithmetic evaluation facility. The syntax is similar to that of formulae in most programming languages; see ifzman(the section `Arithmetic Evaluation' in zmanref(zshmisc))\ -ifnzman(noderef(Arithmetic Evaluation)) for details. The mathematical -library tt(zsh/mathfunc) will be loaded if it is available; see +ifnzman(noderef(Arithmetic Evaluation)) for details. + +Non-programmers should note that, as in many other programming +languages, expressions involving only integers (whether constants +without a `tt(.)', variables containing such constants as strings, or +variables declared to be integers) are by default evaluated using +integer arithmetic, which is not how an ordinary desk calculator +operates. To force floating point operation, pass the option tt(-f); +see further notes below. + +The mathematical library tt(zsh/mathfunc) will be loaded if it is +available; see ifzman(the section `The zsh/mathfunc Module' in zmanref(zshmodules))\ ifnzman(noderef(The zsh/mathfunc Module)). The mathematical functions correspond to the raw system libraries, so trigonometric functions are pws