Newsgroups: comp.ai
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!vixen.cso.uiuc.edu!sdd.hp.com!usc!news.isi.edu!gremlin!charming!mcohen
From: mcohen@charming.nrtc.northrop.com (Martin Cohen)
Subject: Re: Trying to port a decision tree algorithm!
Message-ID: <DGB4qG.9IL@gremlin.nrtc.northrop.com>
Sender: news@gremlin.nrtc.northrop.com (Usenet News Manager)
Organization: Northrop Grumman Automation Sciences Laboratory, Pico Rivera, CA
References: <45gmf7$inn@qns3.qns.com> <45gnec$im3@ixnews4.ix.netcom.com>
Date: Wed, 11 Oct 1995 23:18:15 GMT
Lines: 36

In article <45gnec$im3@ixnews4.ix.netcom.com> adamnet@ix.netcom.com (Jared Shope ) writes:
>In <45gmf7$inn@qns3.qns.com> rking@aig.com writes: 
>>
>>I'm trying to port a decision tree algorithm that is written in C.
>>It has a call to a function log2(n) that I can't find in my C
>libraries.
>>Can anybody tell me what this function does?
>>
>>Thanks,
>>
>>Ron
>
>Looks like it takes the log of n base 2. See something like Numerical
..........

If the purpose is to take the log base 2 of an integer
(rather that a float or double), then you
could do something like this:

int log2(int n)
{
	int i;

	i = 0;
	while ( n >>= 1 ) i++;

	return i;
}

This assumes that n is non-negative.


-- 
Marty Cohen (mcohen@nrtc.northrop.com) - Not the guy in Philly
  This is my opinion and is probably not Northrop Grumman's!
          Use this material of your own free will
