From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9136 invoked by alias); 12 Jan 2015 16:18:35 -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: 34256 Received: (qmail 23269 invoked from network); 12 Jan 2015 16:18:32 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_FSL_HELO_BARE_IP_2 autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1421079503; bh=KIGqoXyaYQDrLa864GQvRe6JJ+TNxSTJjBiVkZRKqx0=; h=From:To:In-Reply-To:References:Subject:Date; b=TQaGjqhTObjhbYHKvamPTLVGMGY7YViI3SqKO3rohJh168xgnwe3i390eYmG+I2pm OfHKs3ioWmhyAArMgfTkn8LHud8Z8Z1h1jNU17muzYKp6PCoLjeVX68sVPNB+3JqLu Iw0oEwUY/chajC3bZuj1jVxBfNh47hW2N5gP+Eio= From: ZyX To: Vincent Lefevre , "zsh-workers@zsh.org" In-Reply-To: <20150112091737.GB27773@xvii.vinc17.org> References: <775A96D9-12A6-499B-8AAB-B2431F13701D@larryv.me> <54B069A9.2040504@eastlink.ca> <54B0D451.1000502@eastlink.ca> <150110085320.ZM28012@torch.brasslantern.com> <54B173ED.20301@eastlink.ca> <150110111445.ZM21328@torch.brasslantern.com> <54B1A5EC.2080202@eastlink.ca> <150110175103.ZM21764@torch.brasslantern.com> <54B205B8.4080208@eastlink.ca> <20150112091737.GB27773@xvii.vinc17.org> Subject: Re: Math expression evaluation error? MIME-Version: 1.0 Message-Id: <1518701421079502@web12g.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 12 Jan 2015 19:18:22 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 12.01.2015, 12:18, "Vincent Lefevre" : > 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. It is not integer division. 1.0/2 and 1/2.0 will give the same result: 0.5. If you want to see language with operator for integer division check out Python-3: it has / for always-floating-point-unless-overridden and // for always-integral-unless-overridden (note: *not* integer (i.e. int type), having float on either side of // will result in floating-point integral value). Though as usual you can do anything you like in your own class, including `rm -rf ~` when trying to use division. I would rather call it “type-specific division”. And I think that Python-3 way is least surprising and most convenient variant. Though you should not use // for dividing non-integral floats: 1.5//0.1 == 14.0 (rounding+decimal-binary conversion issues I guess). > > -- > Vincent Lefèvre - Web: > 100% accessible validated (X)HTML - Blog: > Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)