Ignore:
Timestamp:
06/22/23 03:27:28 (10 months ago)
Author:
Maciej Komosinski
Message:

Turn -0.0 to 0.0 when the allowed range starts at 0.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_math.h

    r1053 r1253  
    3838std::string doubleToString(double x, int precision);
    3939double round(const double x, const int precision);
     40static inline void clipNegativeZeroIfNeeded(double& value, const double range_low)
     41{
     42        if (value == 0.0 && range_low == 0.0) // if we have range_low==0.0 and we get value==-0.0 (which is ==0.0)
     43                value = 0.0; //turn -0.0 to 0.0 so that it does not look like exceeding the allowed range (even though -0.0==0.0). This code unnecessarily also "overwrites" value==0.0 with 0.0, but it is faster and simpler than additionally checking std::signbit(value) just to distinguish -0.0 from 0.0.
     44        //these conditions are not intended for range_low==-0.0, as we assume nobody would define allowed ranges using -0.0.
     45}
    4046
    4147
Note: See TracChangeset for help on using the changeset viewer.