Results 1 to 4 of 4

Thread: Why is there no qSgn() available?

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Why is there no qSgn() available?

    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?

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is there no qSgn() available?

    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:
    Qt Code:
    1. if (qSign(myNumber) == Qt::Positive) ...
    To copy to clipboard, switch view to plain text mode 
    instead of:
    Qt Code:
    1. if (myNumber > 0.0) ...
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Feb 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why is there no qSgn() available?

    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.

  4. #4
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why is there no qSgn() available?

    Quote Originally Posted by snapshooter View Post
    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....

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.