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

Re: Math expression evaluation error?



On 2015-01-10 21:10:16 -0800, Ray Andrews wrote:
> Sure.  That's the best argument for leaving it alone and of course it is
> perfectly sound.  I'd go the other way, liking friendliness more, but
> I respect your decision. And I could be quite wrong about 1/2 + 1/2 = 0,
> strange as it looks to me, rounding down could be vital to some code
> somewhere.

It's only a notation problem. Unfortunately / was chosen (historically,
not by zsh) as the symbol for integer division. The shell expression
1/2 + 1/2 just means:

  integer_div(1,2) + integer_div(1,2)

where integer_div is the integer division function, which gives 0.
This is perfectly correct math.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



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