Re: Problem with base 2 logs and Floor
- To: mathgroup at smc.vnet.net
- Subject: [mg73022] Re: Problem with base 2 logs and Floor
- From: "dimitris" <dimmechan at yahoo.com>
- Date: Mon, 29 Jan 2007 04:43:39 -0500 (EST)
- References: <ephdk1$s2c$1@smc.vnet.net>
Something like?
Block[{Message}, r - Floor[Log[2, r]] - 1 /. r -> 4]
FullSimplify[%]
3 - Floor[Log[4]/Log[2]]
1
Block[{Message}, r - Ceiling[Log[2, r]] - 1 /. r -> 4]
FullSimplify[%]
3 - Ceiling[Log[4]/Log[2]]
1
Block[{Message}, r - Floor[Log[2, r]] - 1 /. r -> 8]
FullSimplify[%]
7 - Floor[Log[8]/Log[2]]
4
Block[{Message}, r - Ceiling[Log[2, r]] - 1 /. r -> 8]
FullSimplify[%]
7 - Ceiling[Log[8]/Log[2]]
4
Dimitris
On Jan 28, 7:50 am, neillcl... at msn.com wrote:
> Hi,
>
> When I use an expression like this:
>
> r - Floor[Log[2, r]] - 1 /. r -> 4
>
> I get precision errors in Mathematica 5.2. If I use an expression like
> this:
>
> N[r - Floor[Log[2, r]] - 1] /. r -> 4
>
> I get a correct result of 1 and no errors. If I use an expression like
> this I get the same result:
>
> N[r - Ceiling[Log[2, r]] - 1] /. r -> 4
>
> This is to be expected as Floor[Log[2, r]] = Ceiling[Log[2, r]] when
> r is a power of two.
> Unfortunatly the expessions diverge for r=8:
>
> N[r - Floor[Log[2, r]] - 1] /. r -> 8 gives 5
> N[r - Ceiling[Log[2, r]] - 1] /. r -> 8 gives 4
>
> How can I get exacts results for expessions like this?
> Thanks.
> Neill.