Click here to Skip to main content
15,899,474 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Object cloning Pin
Orjan Westin31-Jul-14 5:08
professionalOrjan Westin31-Jul-14 5:08 
QuestionWhat MFC class applies to the listbox control in VS2010 resource editor? Pin
Member 1095872129-Jul-14 0:58
Member 1095872129-Jul-14 0:58 
AnswerRe: What MFC class applies to the listbox control in VS2010 resource editor? Pin
«_Superman_»29-Jul-14 1:53
professional«_Superman_»29-Jul-14 1:53 
QuestionNot able to find the square of the floating number ... Pin
mybm128-Jul-14 21:20
mybm128-Jul-14 21:20 
AnswerRe: Not able to find the square of the floating number ... Pin
Jochen Arndt28-Jul-14 21:29
professionalJochen Arndt28-Jul-14 21:29 
GeneralRe: Not able to find the square of the floating number ... Pin
mybm128-Jul-14 23:22
mybm128-Jul-14 23:22 
GeneralRe: Not able to find the square of the floating number ... Pin
Jochen Arndt29-Jul-14 0:32
professionalJochen Arndt29-Jul-14 0:32 
AnswerRe: Not able to find the square of the floating number ... Pin
CPallini29-Jul-14 0:25
mveCPallini29-Jul-14 0:25 
Quote:
double sqrt (double f)
{
double x, z, tempf;
unsigned long *tfptr = ((unsigned long *)&tempf) + 1;
tempf = f;
*tfptr = (0xbfcdd90a - *tfptr)>>1;
x = tempf;
z = f*0.5;
x = (1.5*x) - (x*x)*(x*z); //The more you make replicates of this statement
//the higher the accuracy, here only 2 replicates are used
x = (1.5*x) - (x*x)*(x*z);
return x*f;
}


That is really messy!
You are using uninitialized variables (that is garbage).


It looks you want to implement the Babylonian method[^] but you do nothing for computing the initial guess.
The following code is based on that very Wikipedia page.

C
void initial_guess(double r, int *pa, int *pn)
{
  *pn = 0;

  while ( r < 1.0)
  {
    r *= 100.0;
    --(*pn);
  }
  while ( r >= 100.0 )
  {
    r /= 100.0;
    ++(*pn);
  }

  *pa = (r < 10.0) ? 2 : 6;
}


C
double square_root(double r)
{
  int a, i, n;
  initial_guess(r, &a, &n);
  double x=1.0;

  while (n < 0)
  {
    x/=10.0;
    ++n;
  }
  while(n > 0)
  {
    x *= 10.0;
    --n;
  }

  x *= a;

  for (i = 0; i<10; ++i) // 10 is the arbitrary number of iterations I chose
  {
    x = 0.5 * (x + r/x);
  }

  return x;
}

THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite

GeneralRe: Not able to find the square of the floating number ... Pin
mybm129-Jul-14 1:52
mybm129-Jul-14 1:52 
GeneralRe: Not able to find the square of the floating number ... Pin
CPallini29-Jul-14 1:54
mveCPallini29-Jul-14 1:54 
GeneralRe: Not able to find the square of the floating number ... Pin
mybm129-Jul-14 1:56
mybm129-Jul-14 1:56 
QuestionRe: Not able to find the square of the floating number ... Pin
CPallini29-Jul-14 2:00
mveCPallini29-Jul-14 2:00 
AnswerRe: Not able to find the square of the floating number ... Pin
mybm129-Jul-14 2:47
mybm129-Jul-14 2:47 
GeneralRe: Not able to find the square of the floating number ... Pin
CPallini29-Jul-14 8:07
mveCPallini29-Jul-14 8:07 
GeneralRe: Not able to find the square of the floating number ... Pin
mybm129-Jul-14 18:19
mybm129-Jul-14 18:19 
GeneralRe: Not able to find the square of the floating number ... Pin
CPallini29-Jul-14 21:30
mveCPallini29-Jul-14 21:30 
GeneralRe: Not able to find the square of the floating number ... Pin
jeron129-Jul-14 9:14
jeron129-Jul-14 9:14 
GeneralRe: Not able to find the square of the floating number ... Pin
mybm129-Jul-14 18:20
mybm129-Jul-14 18:20 
Questionmigration from Visual studio 6 Pin
Swap928-Jul-14 3:30
Swap928-Jul-14 3:30 
AnswerRe: migration from Visual studio 6 Pin
Jochen Arndt28-Jul-14 4:03
professionalJochen Arndt28-Jul-14 4:03 
GeneralRe: migration from Visual studio 6 Pin
Swap928-Jul-14 4:34
Swap928-Jul-14 4:34 
GeneralRe: migration from Visual studio 6 Pin
Jochen Arndt28-Jul-14 4:58
professionalJochen Arndt28-Jul-14 4:58 
GeneralRe: migration from Visual studio 6 Pin
Swap928-Jul-14 5:03
Swap928-Jul-14 5:03 
GeneralRe: migration from Visual studio 6 Pin
Jochen Arndt28-Jul-14 5:11
professionalJochen Arndt28-Jul-14 5:11 
GeneralRe: migration from Visual studio 6 Pin
Swap928-Jul-14 11:25
Swap928-Jul-14 11:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.