Mark some limits as constexpr

gcc doesn't need it and computes during compile regardless, but experimenting in godbolt, both clang and MSVC actually do need it or else it's partially computed at runtime


(cherry picked from commit ca7840334c)
This commit is contained in:
Marek Roszko 2022-02-04 07:48:14 -05:00 committed by Mark Roszko
parent 7642a9db79
commit 50d3a507d0
3 changed files with 6 additions and 5 deletions

View File

@ -176,7 +176,7 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties()
int32_t ALTIUM_PARSER::ConvertToKicadUnit( const double aValue )
{
const double int_limit = ( std::numeric_limits<int>::max() - 1 ) / 2.54;
constexpr double int_limit = ( std::numeric_limits<int>::max() - 1 ) / 2.54;
int32_t iu = KiROUND( Clamp<double>( -int_limit, aValue, int_limit ) * 2.54 );

View File

@ -448,7 +448,7 @@ int SCH_SEXPR_PARSER::parseInternalUnits()
// Schematic internal units are represented as integers. Any values that are
// larger or smaller than the schematic units represent undefined behavior for
// the system. Limit values to the largest that can be displayed on the screen.
double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
constexpr double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
}
@ -458,7 +458,7 @@ int SCH_SEXPR_PARSER::parseInternalUnits( const char* aExpected )
{
auto retval = parseDouble( aExpected ) * IU_PER_MM;
double int_limit = std::numeric_limits<int>::max() * 0.7071;
constexpr double int_limit = std::numeric_limits<int>::max() * 0.7071;
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
}

View File

@ -208,7 +208,8 @@ int PCB_PARSER::parseBoardUnits()
// larger or smaller than those board units represent undefined behavior for
// the system. We limit values to the largest that is visible on the screen
// This is the diagonal distance of the full screen ~1.5m
double int_limit = std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
constexpr double int_limit =
std::numeric_limits<int>::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2)
return KiROUND( Clamp<double>( -int_limit, retval, int_limit ) );
}
@ -220,7 +221,7 @@ int PCB_PARSER::parseBoardUnits( const char* aExpected )
// N.B. we currently represent board units as integers. Any values that are
// larger or smaller than those board units represent undefined behavior for
// the system. We limit values to the largest that is visible on the screen
double int_limit = std::numeric_limits<int>::max() * 0.7071;
constexpr double int_limit = std::numeric_limits<int>::max() * 0.7071;
// Use here #KiROUND, not EKIROUND (see comments about them) when having a function as
// argument, because it will be called twice with #KIROUND.