Thread: sqrt()

  1. #1
    Registered User
    Join Date
    Jan 2005


    Can someone explain how the sqrt() function works internally? Thanks.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jun 2004
    asm VC++ sintax
    __declspec(naked) float sqrt(float num){
    	FLD dword ptr [esp+4]
    	FIST dword ptr [esp+4]
    	mov eax, dword ptr [esp+4]
    int main(){
    	float i;
    		printf("sqrt of %f is %f\n",i,sqrt(i));
    	return 0;
    Hum. I was having troubles when using 'num' instead of 'dword ptr [esp+4]' because the compiler was translating the num var adress as esp+8..... so I hard typed the adress every time.
    actually if you debug the app and view the dissassembly, sqrt will call about 40 asm instrutions... don't ask me why...
    Last edited by xErath; 06-01-2005 at 12:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2006, 04:37 PM
  2. sqrt() function help
    By willc0de4food in forum C Programming
    Replies: 5
    Last Post: 03-14-2005, 09:07 PM
  3. SQRT Mystery...
    By KneeLess in forum C Programming
    Replies: 7
    Last Post: 03-23-2004, 07:49 AM
  4. sqrt
    By modec in forum C Programming
    Replies: 3
    Last Post: 04-16-2003, 07:19 AM
  5. how sqrt ?
    By sambs1978 in forum C Programming
    Replies: 3
    Last Post: 09-20-2001, 08:14 AM