From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29076 invoked by alias); 18 May 2015 08:27:22 -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: 35178 Received: (qmail 1271 invoked from network); 18 May 2015 08:27:18 -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:16:16 +0200 From: Vincent Lefevre To: Lawrence =?iso-8859-1?Q?Vel=E1zquez?= Cc: Emanuel Berg , zsh-workers@zsh.org Subject: Re: why do ceil/floor give the decimal dot? Message-ID: <20150518081616.GA25036@ypig.lip.ens-lyon.fr> Mail-Followup-To: Lawrence =?iso-8859-1?Q?Vel=E1zquez?= , Emanuel Berg , zsh-workers@zsh.org References: <87oalodmns.fsf@debian.uxu> <150513195617.ZM29493@torch.brasslantern.com> <87d223et0a.fsf@debian.uxu> <20150514105349.52338d94@pwslap01u.europe.root.pri> <87siay262s.fsf@debian.uxu> <14C892AF-61F9-4FEE-832C-0AD196669182@larryv.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <14C892AF-61F9-4FEE-832C-0AD196669182@larryv.me> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6449-vl-r76280 (2015-05-18) On 2015-05-14 18:14:53 -0400, Lawrence Velázquez wrote: > On May 14, 2015, at 5:38 PM, Emanuel Berg wrote: > > > I like the solution better to have the types all > > floats (or whatever) and then use printf to make it > > look the way you want. > > You should use %g then (with appropriate precision) because %d does an > implicit conversion. > > % printf '%d\n' $(( 1e20 )) > -9223372036854775808 > > % printf '%g\n' $(( 1e20 )) > 1e+20 > > % printf '%.30g\n' $(( 1e20 )) > 100000000000000000000 To output integers, it may be better to use %.0f because %g may output the result with an exponent, or use a very large precision for %g so that it wouldn't depend on the number to output, such as %.9999g (but %.0f is shorter and simpler to understand). Now, if the user restricts to the range where all integers are representable as floating point, i.e. [-2^53,2^53], then %.16g is sufficient. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)