Support Board
Date/Time: Sun, 08 Sep 2024 02:02:07 +0000
Post From: Suggestion to remove compiler warnings C26451 for Round() in sierrachart.h
[2023-11-29 21:28:43] |
User719512 - Posts: 244 |
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. |