|
Logarithms in different bases can be done using the formula
logy x = logz x / logz y
So you can use the log or log10 function to produce an approximate log2 function:
double log2(double val)
{
return log(val) / log(2.0);
}
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Argh, beat me to it! You must have posted that while I was in the process of replying.
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|
Perfect! Thanks so much!
"It seems that we're getting to the bottom of the barrel of squirrels." - my boss
|
|
|
|
|
Use the Magic Log Forumla:
Logb x = Loga x/Loga b
A funcion that can get an arbitrary log:
double MyLog(double base, double x)
{
return log10(x) / log10(base);
}
...
double a = MyLog(2, 16);
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|
just a curiosity and "personal culture" question...
what should we need a Base-2 log for ??
very thank you
TOXCCT >>> GEII power
|
|
|
|
|
A whole world of it:
Check on google log neperien
In breif:
Solving mathematical equations
Mathematical modeling of the movement of protons
Spatial Interpolation,
Mechanical modeling
Probability and statistics ....
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
wow woww stop it man, did you read my post ???
i didn't ask for log neperien (which is a Base-e log), but the need for having a log2 one !!!!
TOXCCT >>> GEII power
|
|
|
|
|
Sorry for missreading your post
log2 is used in music among others for as octave utility
and for floating point arithmetics:
"By knowing that the exponent and mantissa are both two's compliment values and also knowing that a floating point number is a very close approximation of the same number expressed in log2 form, a quick inversions and square roots can be implimented with simple functions. For example a quick inverse is calculated by negating the exponent and mantissa bits."
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
|
toxctt wrote:
what should we need a Base-2 log for ??
Since computers use base-2 numbers, binary logarithms come in very handy. For example, what is the next highest power of two for the number 79?
int x = 1 + (int) log2(79);
If a binary tree has N nodes, what is the minimum number of levels in the tree? log2(13) + 1 yields the answer of 4.
http://www.encyclopedia4u.com/b/binary-logarithm.html
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
oh, that's nice ! lol
but since it's very useful, how to find such expression ? did you find such by yourself, or with docs ?
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
oh, that's nice ! lol
Are you laughing facetiously?
toxcct wrote:
how to find such expression ?
What expression?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
DavidCrow wrote:
Are you laughing facetiously?
no, i promise you i find all these very nice...
DavidCrow wrote:
What expression?
such expression : int x = 1 + (int) log2(79);
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
such expression : int x = 1 + (int) log2(79);
I just made that statement up. A log2() function does not exist in the standard library, so if you needed one, it would have to be created.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
DavidCrow wrote:
log2() function does not exist in the standard library
yes, that was implicit and understood.
what i want to know is about the entiere expression (int x = 1 + (int) log2(79); ) ; did you find it after been documented, or by a thinking of your own ?
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
did you find it after been documented, or by a thinking of your own ?
The latter. Since log2(79) is 6.3, I needed to take the integer part of that and add one, yielding 7. Thus 27 is 128, the next highest power of 2 for the number 79.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
This expression is a solution to the problem DavidCrow presented: "-- What is the next highest power of two for the number 79?"
The expression first evaluates the power to which 2 must be raised to reach 79, then adds 1 to this. It all bases on the way logarithms are defined: "Base N logarithm from number Y will result in the power to which N must be raised to result in Y".
Most obviously, he just made up a quick problem, and solved it, to give an example. So, he thought it on his own, made it up.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Aaaarrrrgggghhh!! you really want to compute binary logarithm of integers with float logarithm function? I think that integer approach would be much much more quicker:
int log2(int x)
{
int lg;
for(lg = -1; x != 0; x /= 2, lg++);
return lg;
}
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
Robert A. T. Káldy wrote:
...with float logarithm function
The log2() function I demonstrated was theoretical. Were it to be implemented, int s would surely be used over double s.
Robert A. T. Káldy wrote:
I think...
But without actual metrics, we don't really know.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi,
Is there a way to Kill a process programatically, something like :
KillProcess (name) ?
I want to kill a process which I can see in the process list of CTRL+ALT+DEL and I want to make sure it's not there before doing something.
Thanks,
Shay
|
|
|
|
|
One lame way to do so:
http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
you can issue a call to pskill or do your own using
or open the process and issue a call to TerminateProcess
or using
http://www.codeproject.com/threads/pausep.asp
and replacing the SuspendThread by TerminateThread
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hi,
Is there a way to Kill a process programatically, something like :
KillProcess (name) ?
I want to kill a process which I can see in the process list of CTRL+ALT+DEL and I want to make sure it's not there before doing something.
Thanks,
Shay
|
|
|
|
|
Hi anybody has any idea about this : how to print a html file (in html format , not text format) without showing any printer dialog and being able to customize the orientation (portrait/landscape) . Any links are welcome
Thanks
xxx
|
|
|
|
|
Hi guys
When my App is running in W98 I receive sometimes a "Resource necessary non available".
There is a way to avoid this message in W98? Programatically? With an utility?
Best Regards
Doc
|
|
|
|
|
At the point in which the message is displayed, what resource is your application asking for (e.g., bitmap, icon, menu, dialog, string table)?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|