41 #define wxASCII_STR(s) wxString::FromAscii(s)
46 if( wxLog::IsLevelEnabled( wxLOG_Debug, wxString::FromAscii( wxLOG_COMPONENT ) ) )
49 va_start( argList, aFormatString );
51 wxVLogWarning( aFormatString, argList );
60 wxString typeName( aTypeName );
61 wxFAIL_MSG( wxString::Format( wxT(
"\n\nOverflow converting value %f to %s." ), v, typeName ) );
66int rescale(
int aNumerator,
int aValue,
int aDenominator )
68 int64_t numerator = (int64_t) aNumerator * (int64_t) aValue;
71 if( ( numerator < 0 ) ^ ( aDenominator < 0 ) )
72 return ( numerator - aDenominator / 2 ) / aDenominator;
74 return ( numerator + aDenominator / 2 ) / aDenominator;
80int64_t
rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator )
82#if defined( _M_X64 ) && ( _MSC_VER >= 1920 )
84 uint64_t productLo =
static_cast<uint64_t
>( _mul128( aNumerator, aValue, &productHi ) );
86 int64_t r = ( ( productHi < 0 ) ^ ( aDenominator < 0 ) ) ? -aDenominator / 2 : aDenominator / 2;
88 uint64_t rLo =
static_cast<uint64_t
>( r );
89 int64_t rHi = r < 0 ? -1ll : 0ll;
92 productHi += rHi + ( productLo < rLo );
97 int64_t result = _div128( productHi, productLo, aDenominator, &remainder );
101 __except( ( GetExceptionCode() == EXCEPTION_INT_OVERFLOW ) ? EXCEPTION_EXECUTE_HANDLER
102 : EXCEPTION_CONTINUE_SEARCH )
104 kimathLogDebug(
"Overflow in rescale (%lld * %lld + %lld) / %lld", aNumerator, aValue, r,
110#elif defined( __SIZEOF_INT128__ )
111 __int128_t numerator = (__int128_t) aNumerator * (__int128_t) aValue;
113 if( ( numerator < 0 ) ^ ( aDenominator < 0 ) )
114 return ( numerator - aDenominator / 2 ) / aDenominator;
116 return ( numerator + aDenominator / 2 ) / aDenominator;
120 int64_t
sign = ( ( aNumerator < 0 ) ? -1 : 1 ) * ( aDenominator < 0 ? -1 : 1 ) *
121 ( aValue < 0 ? -1 : 1 );
125 int64_t c =
std::abs( aDenominator );
129 if( b <= std::numeric_limits<int>::max() && c <= std::numeric_limits<int>::max() )
131 if( a <= std::numeric_limits<int>::max() )
132 return sign * ( ( a * b + r ) / c );
134 return sign * ( a / c * b + ( a % c * b + r ) / c);
138 uint64_t a0 = a & 0xFFFFFFFF;
139 uint64_t a1 = a >> 32;
140 uint64_t b0 = b & 0xFFFFFFFF;
141 uint64_t b1 = b >> 32;
142 uint64_t t1 = a0 * b1 + a1 * b0;
143 uint64_t t1a = t1 << 32;
147 a1 = a1 * b1 + ( t1 >> 32 ) + ( a0 < t1a );
149 a1 += a0 < (uint64_t)r;
151 for( i = 63; i >= 0; i-- )
153 a1 += a1 + ( ( a0 >> i ) & 1 );
156 if( (uint64_t) c <= a1 )
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
int rescale(int aNumerator, int aValue, int aDenominator)
void kimathLogOverflow(double v, const char *aTypeName)
Workaround to avoid the empty-string conversion issue in wxWidgets.
void kimathLogDebug(const char *aFormatString,...)
Helper to avoid directly including wx/log.h for the templated functions in kimath.
constexpr int sign(T val)