Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Math expression evaluation error?
- X-seq: zsh-workers 34196
- From: Lawrence Velázquez <vq@xxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: Math expression evaluation error?
- Date: Fri, 9 Jan 2015 18:06:56 -0500
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=larryv.me; h= x-sasl-enc:content-type:mime-version:subject:from:in-reply-to :date:cc:content-transfer-encoding:message-id:references:to; s= mesmtp; bh=pp20zOwSm0UQFiT93xuu35NR+y8=; b=T1w3a2ouJPwRuDRhsckTV lgOhDr3DATmO8Za8WWOYjrmgq83+CyUrq/8dQtXn+cKY2FYBD1hut9eHyYU2ZPpW UNmfx4bQyQSMay5YC7b5NbxJLOQ49gHyorv7y4G2LmSvVLc7hj61vFBYNGTZFSgU DHlBxoDrGGIV5Kt+dZnnQ4=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:content-type:mime-version :subject:from:in-reply-to:date:cc:content-transfer-encoding :message-id:references:to; s=smtpout; bh=pp20zOwSm0UQFiT93xuu35N R+y8=; b=VbZJYuXShJzxPgFNB/tLUhHAXgReJH1dlmZ/ksfauFTvk3x5JRav/te igZU4mCDc2HZ0FmMDc9ZeDSyvU9WR7RW03UV5SelkbXKQpsqL+9S6g32gBOFIzJW w0B6L4fj6wvILROBTj2N4DplWMsn8bczIVC7LZ0wNqe0aG788mGE=
- In-reply-to: <54B05407.7090303@eastlink.ca>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <54B03024.1030309@gmail.com> <20150109201552.1304eafe@ntlworld.com> <54B04ADA.9050102@gmail.com> <54B05407.7090303@eastlink.ca>
On Jan 9, 2015, at 5:19 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> I wonder tho why anyone would ever want the first set of results. Who/why/when
> do we want bad math?
Mathematics restricted to the set of integers is not "bad math", no matter how much you assert that it is.
> Wouldn't we prefer accurate results as the default with the option to have broken math for people who like broken math?
Stop calling it "broken". It's the way C does math.
% clang -Wno-format -o c-integer-div -x c - <<EOF
heredoc> #include <stdio.h>
heredoc> int main(void) {
heredoc> printf("integer division is not 'bad math': 3 / 8 = %f\n", 3 / 8);
heredoc> return 0;
heredoc> }
heredoc> EOF
% ./c-integer-div
integer division is not 'bad math': 3 / 8 = 0.000000
At this point, this is what a lot of programmers expect, especially since the rest of zsh's arithmetic is quite C-like.
> Why not have it work properly and that's that--nothing to explain, it just works as you'd expect it to work?
It'd work as YOU expect it to work. Plenty of other people expect it to work like C, and we'd have to explain to them why it doesn't. (We already have to do so for operator precedence and hexadecimal literals, among other things.)
> 6 + 3/8 + 10 + 5/8 ...
> what sane calculator is going to give me '16' for that?
zsh is not a calculator.
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author