Re: Problem with base 2 logs and Floor

• To: mathgroup at smc.vnet.net
• Subject: [mg73011] Re: [mg73001] Problem with base 2 logs and Floor
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Mon, 29 Jan 2007 03:59:31 -0500 (EST)
• References: <200701280611.BAA29002@smc.vnet.net>

```On 28 Jan 2007, at 07:11, neillclift 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.
>

Make sure that Mathematica does not attempt numerical evaluation
before the value of r is substituted in. One way to do this is:

In[1]:=
Unevaluated[r - Floor[Log[2, r]] - 1 ]/. r -> 8

Out[1]=
4

In[2]:=
Unevaluated[r-Ceiling[Log[2,r]]-1]/. r -> 8

Out[2]=
4

Andrzej Kozlowski

```

• Prev by Date: Irregular Behavior of TranslateShape and RotateShape with ParametricPlot3D
• Next by Date: Re: Problem with base 2 logs and Floor
• Previous by thread: Problem with base 2 logs and Floor
• Next by thread: Re: Problem with base 2 logs and Floor