sqrtf function

This is a discussion on sqrtf function within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have this function to compute for the distance between two given points. I have been getting this ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    Smile sqrtf function

    Hi all,
    I have this function to compute for the distance between two given points. I have been getting this error:

    Code:
    error C2064: term does not evaluate to a function taking 1 arguments
    Code is as follows:
    Code:
    float dist(float ax, float ay, float az, float bx, float by, float bz)
    {
    	float d = 0.0f, dist = 0.0f;
    	
    	distance = ((bx-ax)(bx-ax)+(by-ay)(by-ay)+(bz-az)(bz-az));
    	d = sqrtf(distance);
    	cout << d << endl;
    	return d;
    }
    I think I wasn't able to put the formula in the best code format.
    Any ideas?

    Thanks...

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    distance = ((bx-ax)*(bx-ax)+(by-ay)*(by-ay)+(bz-az)*(bz-az));
    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
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91
    Oh.. the error points to the line where the distance computation is.. The function has six parameters hence, six arguments, right?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    #include <iostream>
    #include <cmath>
    using std::cout;
    using std::endl;
    
    float dist(float ax, float ay, float az, float bx, float by, float bz)
    {
    	float d = 0.0f, dist = 0.0f;
    	
    	dist = ((bx-ax)*(bx-ax)+(by-ay)*(by-ay)+(bz-az)*(bz-az));
    	d = sqrtf(dist);
    	cout << d << endl;
    	return d;
    }
    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.*

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    Smile

    Thanks a lot, Dave... I got it working right away..
    It's funny I often overlook simple, important details like that..
    Thanks again..

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I would recommend that you don't use the same name for a function and a variable inside the function. Whilst it's perfectly legal and valid to do, it can confuse almost any reader.

    Of course, aside from debug purposes, there's no reason to calculate intermediate values at all - just stuff the whole computation into the arguments to sqrtf() and be done with it.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Did you edit the code in your original post?

    Please don't do that. It confuses people who later read the thread.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91
    Thanks, matsp... I will try not to.
    No, I didn't edit it, CornedBee...

    Thanks..

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Ah, I see what was wrong. I wondered how Dave got to the pink parts in his code. Didn't see the declaration.

    Just proof of what matsp said.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    My bad. I didn't really look at the function name, only the variable declared above the assignment which didn't seem to come from anywhere. The highlights were just my way of saying "look here". But I should have changed the variable declaration instead.
    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.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21