From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7538 invoked by alias); 18 May 2015 08:39:20 -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: 35180 Received: (qmail 16019 invoked from network); 18 May 2015 08:39:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Date: Mon, 18 May 2015 10:39:17 +0200 From: Vincent Lefevre To: Bart Schaefer Cc: zsh-workers@zsh.org, Emanuel Berg Subject: Re: why do ceil/floor give the decimal dot? Message-ID: <20150518083917.GB25036@ypig.lip.ens-lyon.fr> Mail-Followup-To: Bart Schaefer , zsh-workers@zsh.org, Emanuel Berg References: <87oalodmns.fsf@debian.uxu> <150513195617.ZM29493@torch.brasslantern.com> <87d223et0a.fsf@debian.uxu> <150513210405.ZM29616@torch.brasslantern.com> <87oalncyjw.fsf@debian.uxu> <150514105426.ZM30800@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <150514105426.ZM30800@torch.brasslantern.com> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6449-vl-r76280 (2015-05-18) On 2015-05-14 10:54:26 -0700, Bart Schaefer wrote: > No, I mean that looking at this: > > torch% float X=27 > torch% print $X > 2.700000000e+01 > torch% print $(( X )) > 27. > torch% printf "%f\n" $X > 27.000000 > torch% printf "%g\n" $X > 27 > > One might wonder why there are four different representations of the > same number, and we could therefore discuss whether some of them should > be unified. This is not the same discussion as whether they should be > converted to integers. Concerning the accuracy: ypig% float x=$((1./3)) ypig% print $x 3.333333333e-01 ypig% print $((x)) 0.33333333333333331 ypig% printf "%f\n" $x 0.333333 ypig% printf "%g\n" $x 0.333333 The last two are specified by C, and I suppose that $((x)) gives full accuracy, i.e. if the decimal number is re-read as a floating-point value, the original value must be recovered exactly. Concerning the first one, I wonder why there are "typeset -E" (default for "float" as used above) and "typeset -F". The way a value is output shouldn't come from its declaration. IMHO, there should be a single floating-point datatype, not one for each output format. BTW, there is a bug in zsh 5.0.7: ypig% typeset -F 3 x=$((17)) ypig% print $x 17.000 ypig% typeset -F 2 x=$((17)) ypig% print $x 17.00 ypig% typeset -F 1 x=$((17)) typeset: invalid base (must be 2 to 36 inclusive): 1 It is not a base here. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)