PDA

View Full Version : Why is there no qSgn() available?



Cruz
11th February 2009, 10:37
While a number of commonly needed basic math functions can be used, such as qSin() or qSqrt(), how come Qt is not offering a qSgn() function to determin the sign of a real?

boudie
11th February 2009, 21:55
Thinking about how to implement such function; would it make life easier?

It should return something like Qt::Negative or Qt::Positive or Qt::Zero so you can write:

if (qSign(myNumber) == Qt::Positive) ...
instead of:

if (myNumber > 0.0) ...

I don't think I would use qSign()... ;)

snapshooter
12th February 2009, 05:11
Actually the (mathematical) definition of Sgn(x) function is 1 if x > 0, 0 if x=0 and -1 if x < 0. And indeed there are some uses for it.

seneca
12th February 2009, 06:56
Actually the (mathematical) definition of Sgn(x) function is 1 if x > 0, 0 if x=0 and -1 if x < 0. And indeed there are some uses for it.

But would the compare with 0 then have to be exact as x == 0.0, or by qFuzzyCompare(x,0.0)?

I think I could not live without two distinct functions then.... :rolleyes: