Re: Math Error in the .NET Framework 1.1.4322 SP1

Tech-Archive recommends: Fix windows errors by optimizing your registry



> Dividing log x by log y is /a/ way of getting log base y of x, not
> /the/ way.

Actually, if you use ILDASM to look at mscorlib.dll, you will find that
the overloaded function System.Math.Log(double a, double newBase) actually
calls System.Math.Log(double d) twice. Internally, it does take log x / log
y, which actually makes this even more puzzling as doing that yourself works.

> The difference is 1 LSB (the "wrong" value is 4007FFFFFFFFFFFF, the
>"right" value is 4008000000000000), so I think being concerned about
>the accuracy is probably futile.

In my case, the difference is everything. If you are using the bits of an
integer as an array of boolean values (needed given the algorithm that I am
running) then this calculation is a nightmare. In the calculation, you take
the log of the value and pass it to the floor function to get the set bit. In
the given example, the set bit is actually the 3rd, but the calculation will
give you the 2nd.

There are also other powers of 2 that are off. The odd thing here is that
certain powers are off when run from within the IDE and different ones are
off when run from the command line. I computed the first 64 powers of 2 and
confirmed that 9 of them are off when run inside the IDE. There are 12 powers
of 2 that are off if run from the command line. Other than 51, 55 and 59, all
of the powers are different depending on whether you run the program inside
the IDE or outside of it. Try the following code:

for(int i = 1;i < 64;i++)
{
if(System.Math.Log(System.Math.Pow(2,i),2) != i)
Console.WriteLine(i.ToString());
}

Also, I tried this same calculation using log x / log y and found that 9
powers of 2 are off, but they are different than the ones that are off using
the overloaded method. Additionally, these are the same whether run inside
the IDE or outside of it.

Lastly, I used VB 6.0 to compute these first 64 powers of 2 and it
checked out fine. It's unsettling to me that VB 6.0 can get it right, but
..NET cannot.
.



Relevant Pages

  • Power Of The Day -- Lyndon
    ... calculations for the challenge totals. ... Powers, Emotion Control, ... loss for the challenge only regards the second calculation. ... You may use your power as a main player. ...
    (rec.games.board.ce)
  • Power Of The Day -- Lyndon
    ... calculations for the challenge totals. ... Powers, Emotion Control, ... loss for the challenge only regards the second calculation. ... You may use your power as a main player. ...
    (rec.games.board.ce)
  • Re: Computing pi to nth terms?
    ... I am attempting to pass powers of two, from one to 16777216, to a ... the calculation of pi using ... the int created in the first loop, ... Kai-Uwe Bux wrote: ...
    (comp.lang.cpp)
  • Re: Computing pi to nth terms?
    ... >I am attempting to pass powers of two, from one to 16777216, to a ... >calculation that approximates pi for each respective power of two ... the calculation of pi using ... You don't need a second loop, its easier than that, see my last two posts. ...
    (comp.lang.cpp)