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

Re: Math expression evaluation error?



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