What's the difference between the math.h and qmath.h??
I mean, if I need to call a square root function whats the difference between sqrt() and qSqrt()?
And where can I find a square function?
What's the difference between the math.h and qmath.h??
I mean, if I need to call a square root function whats the difference between sqrt() and qSqrt()?
And where can I find a square function?
One is a standard C header, the other is part of Qt.
sqrt() is the standard C function defined for double.I mean, if I need to call a square root function whats the difference between sqrt() and qSqrt()?
qSqrt() is a Qt function defined in terms of qreal, either a float or double depending on platform, which calls a type specific sqrt() implementation. Read the header file for more details.
There should be no difference in result on most platforms where qreal == double.
You are joking, aren't you?And where can I find a square function?
BTW: Asking the same thing in two places is bad form.
No, I'm not. I know that I can do x*x, and that is very simple to implement a function to do that. But I though that it was a standart funtion like in pascal, where you can call sqr().You are joking, aren't you?
If you REALLY wanted to use a standard function, you could always call pow(x,2), but sqr() does not exist.
Note that pow() normally uses a polynomial series to do its computation, which will result in a LOT more math operations than simply multiplying two numbers once.
A lot of people use a macro to perform this operation if they want to explicitly say SQR(x).
The parentheses are deliberate and necessary to avoid surprises. Compare these results:
Qt Code:
#define SQR(x) ((x)*(x)) y = 270.0 / SQR(3 + 3); // y = 7.5 as expected #define SQR(x) (x)*(x) y = 270.0 / SQR(3 + 3); // y = 270.0, slightly confusing #define SQR(x) x*x y = 270.0 / SQR(3 + 3); // y = 102, huh!To copy to clipboard, switch view to plain text mode
You could define an inline free function to do it. This gives you type checking that the macro will not and can (possibly) be inlined to avoid function call overhead.
Last edited by ChrisW67; 23rd April 2011 at 03:49.
digog (24th April 2011)
Thanks, that resolved my problem.
Bookmarks