Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

java - Calculate the number of times to divide by two -


greetings.

i have java method consider expensive, , i'm trying replace calls mathematical expression. problem is, suck @ math. mean really suck.

the following should explain pattern i'm trying exploit.

f(x)   -> y f(x*2) -> f(x)+1 

that is, whenever double value x, value y 1 greater x/2. here example output:

f(5)   -> 6 f(10)  -> 7 f(20)  -> 8 f(40)  -> 9 f(80)  -> 10 f(160) -> 11 f(320) -> 12 

my current approach brute force. i'm looping on x , test how many times can halve before reach 5, , add 6. works , faster call original method. looking more "elegant" or potentially cheaper solution.

accepted answer goes 1 manages me without pointing out how stupid :)

(the title sucks, because don't know i'm looking for)

have considered looking @ divide five, find power of 2 have, , add 6 power?

the general approach "given y find out power of x is" use logarithms. calculator try dividing log of 64 log of 2 , see 6.

so - divide five, take log, divide log of two, , add six.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -