# sqrtf function

Printable View

• 11-03-2007
alyeska
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...
• 11-03-2007
Dave_Sinkula
Code:

distance = ((bx-ax)*(bx-ax)+(by-ay)*(by-ay)+(bz-az)*(bz-az));
• 11-03-2007
alyeska
Oh.. the error points to the line where the distance computation is.. The function has six parameters hence, six arguments, right?
• 11-03-2007
Dave_Sinkula
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;
}

• 11-03-2007
alyeska
Thanks a lot, Dave... I got it working right away..
It's funny I often overlook simple, important details like that..:)
Thanks again..:o
• 11-03-2007
matsp
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
• 11-03-2007
CornedBee
Did you edit the code in your original post?

Please don't do that. It confuses people who later read the thread.
• 11-03-2007
alyeska
Thanks, matsp... I will try not to. :)
No, I didn't edit it, CornedBee...

Thanks..
• 11-03-2007
CornedBee
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.
• 11-03-2007
Dave_Sinkula
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.