Results 1 to 3 of 3

Thread: In Linux round() NAN float, return negative garbage values

  1. #1
    Join Date
    Jun 2015
    Posts
    104
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default In Linux round() NAN float, return negative garbage values

    Hello,

    I'm trying to do something like below,

    Qt Code:
    1. float realValue = 5.2;
    2. float nanValue = NAN;
    3. qDebug()<<"realValue"<<round(realValue)<<"nanValue"<<round(nanValue);
    To copy to clipboard, switch view to plain text mode 

    Output in Linux:
    Qt Code:
    1. realValue 5 nanValue -2147483648
    To copy to clipboard, switch view to plain text mode 

    Here for NAN value, it's giving negative value. Is there any alternative for this or how should I handle this in Linux?

    I'm using these values to set the size of variable and size cannot be negative nor NAN.

    Again, if anyhow I tried to figure out NAN value, then added with NAN value is always NAN.
    Qt Code:
    1. qDebug()<<"Output is: "<<(NAN+90)
    2. //Output:
    3. Output is: NAN
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Last edited by npatil15; 29th January 2020 at 05:14.

  2. #2
    Join Date
    Jul 2008
    Posts
    424
    Thanks
    9
    Thanked 54 Times in 52 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: In Linux round() NAN float, return negative garbage values

    Hi, not sure what you want to do. If your size cannot be NAN, then why use it?

    In C++11 you can check for NAN using isnan().

    Ginsengelf

  3. #3
    Join Date
    Jun 2015
    Posts
    104
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: In Linux round() NAN float, return negative garbage values

    Hi,

    Because some time it will be real value not NAN everytime.
    And thanks, isnan() will work.

Similar Threads

  1. qwtplot drawing lines with negative values
    By dimbor2708 in forum Qwt
    Replies: 2
    Last Post: 14th April 2017, 14:00
  2. Replies: 1
    Last Post: 24th November 2016, 08:04
  3. Reading float values from binary file
    By shivendra46d in forum Newbie
    Replies: 0
    Last Post: 4th January 2016, 11:03
  4. Replies: 6
    Last Post: 1st February 2013, 08:32
  5. QDoubleSpinBox and Float Values
    By George Neil in forum Qt Programming
    Replies: 9
    Last Post: 5th August 2008, 20:22

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.