Login Page - Create Account

Support Board


Date/Time: Sun, 03 Mar 2024 23:09:07 +0000



Suggestion to remove compiler warnings C26451 for Round() in sierrachart.h

View Count: 165

[2023-11-29 21:28:43]
User719512 - Posts: 219
Hi Sierra Chart Engineering,

Suggestion to resolve compiler warings when building with Visual Studio.

int Round(float Number)
should use floats for constants to avoid C26451. Use 0.0f instead of 0.0, which is a double not a float. Yes, the code works just fine as-is, but always good to fix this low hanging fruit when possible.

  int Round(float Number)
  {
    int IntegerResult = static_cast <int>(Number);

    if ((Number > 0.0f) && ((Number-IntegerResult) >= 0.5f))
      return ++IntegerResult;
    else if ((Number < 0.0f) && ((Number - IntegerResult) <= -0.5f))
      return --IntegerResult;

    return IntegerResult;

  }  

Perhaps while there, also make an aesthetic change for Round64 and change .5 to be 0.5. Then both Round/Round64 will match visually and be more appealing.


  int64_t Round64(double Number)
  {
    int64_t IntegerResult = static_cast <int64_t>(Number);

    if ((Number > 0.0) && ((Number - IntegerResult) >= 0.5))
      return ++IntegerResult;
    else if ((Number < 0.0) && ((Number - IntegerResult) <= -0.5))
      return --IntegerResult;

    return IntegerResult;

  }

Thank you for your consideration.
[2023-11-30 16:08:21]
Sierra_Chart Engineering - Posts: 13073
We will look this over. But normally using 0.0 does not cause a compiler warning.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2023-11-30 16:08:28
[2023-11-30 22:00:18]
User719512 - Posts: 219
It's the f in 0.0f that makes the compare a float/float in my suggestion for Round() rather than 0.0 which is a double and makes the compare float/double and gives C26451.
The code work of course as-is, but with the warning.

Thanks again for taking a look.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account