From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24006 invoked by alias); 14 May 2015 23:24:17 -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: 35141 Received: (qmail 11787 invoked from network); 14 May 2015 23:24:12 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-workers@zsh.org To: zsh-workers@zsh.org From: Emanuel Berg Subject: Re: why do ceil/floor give the decimal dot? Date: Fri, 15 May 2015 01:29:18 +0200 Message-ID: <87d22220xd.fsf@debian.uxu> 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=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-66.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:rIZXADw4Gw07bKUSANdYJqzWYnw= Lawrence Velázquez writes: >> 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 OK, case closed: prefix-len () { local hosts=$1 local len=$(( 32 - ceil(log($hosts)/log(2)) )) printf "%g\n" $len } $ prefix-len 30 27 Thanks everyone. -- underground experts united http://user.it.uu.se/~embe8573