Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: why do ceil/floor give the decimal dot?
- X-seq: zsh-workers 35119
- From: Lawrence Velázquez <vq@xxxxxxxxx>
- To: Emanuel Berg <embe8573@xxxxxxxxxxxxx>
- Subject: Re: why do ceil/floor give the decimal dot?
- Date: Wed, 13 May 2015 23:53:53 -0400
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=larryv.me; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=qjkuVouGibV3XTfhwKOEXbhexD4=; b=O31Ja6 mK8IZQD5HsavAvO/Xb8WZp12IPtVYd3caDXEVLSmC0i8E9lcljsDDcZFbYftP6Cz 6q/BUJgre9gqHnTDb9EZAVqAJqV6fwV740NtlHkS3Bl7o+nwBxVbIb/BUEgvseNJ pStnIpuQJzRiR6ZDMRZNPWkqj8E5swx7BQz0E=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=qjkuVouGibV3XTf hwKOEXbhexD4=; b=JzyHvQ/cS9gT0rcaKGG7KKetS+YE9UvQ2Tmxj3hzI4UJHCA Cjng9qcmKJW0fa0rjEHPtty++3CN0C1ZRXKw1lf1gL4GfPeRWaGPP3pGNQJ9aFw9 E7nNNNIHYzPyCs3v44BoG7tGVXQTlC1AWY8zEJ5gPDH2leyjVQj0Ck+iY/pI=
- In-reply-to: <87d223et0a.fsf@debian.uxu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <87oalodmns.fsf@debian.uxu> <150513195617.ZM29493@torch.brasslantern.com> <87d223et0a.fsf@debian.uxu>
On May 13, 2015, at 11:29 PM, Emanuel Berg <embe8573@xxxxxxxxxxxxx> wrote:
> Take a look at this [1] zsh:
>
> prefix-len () {
> local hosts=$1
> echo $(( 32 - int(ceil(log($hosts)/log(2))) ))
> }
>
> without the integer conversion, the output for
>
> prefix-len 30
>
> isn't 27, but "27."
Yes, this is expected and correct. From "ARITHMETIC EVALUATION" in the
zshmisc(1) man page:
Promotion of integer to floating point values is performed where
necessary.
So:
- "ceil(log(30)/log(2))" returns floating-point "5."
- integer "32" is promoted to floating point "32."
- floating point "32." - floating point "5." = floating-point "27."
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author