Para comparar dos float o doubles deberíamos hacer:
float myNumber;
float yourNumber;
if( fabs (myNumber - yourNumber) < 0.00001 )
printf("They are close enough") ;
Para comparar dos float o doubles deberíamos hacer:
float myNumber;
float yourNumber;
if( fabs (myNumber - yourNumber) < 0.00001 )
printf("They are close enough") ;
#include <cmath>
#include <limits>
// log10(x) == (n - 1) digits
// (1 + n + fff) == number of digits
// fff == floating-point fudge factor
int digits(int number)
{
// Avoid doing work if number is 0
if (number != 0)
{
double lg = std::log10(static_cast<double>(std::abs(number)));
double eps = std::numeric_limits<double>::epsilon();
return static_cast<int>(1 + lg + eps);
}
else
return 1;
}
// Count until 0 and chop of every tenth
int digits2(int num)
{
// Avoid doing work if number is 0
if (num != 0)
{
int n = 0;
while (num > 0)
{
++n;
num /= 10;
}
return n;
}
else
return 1;
}
¡Se puede mejorar haciendo uso de las funciones de la siguiente entrada!
void IncName( StringC& strName, int nCount, int nMaxChars )
{
int nCountDigit = 1;
while( (nCount / pow(10.0,nCountDigit)) >= 1.0 )
{
nCountDigit++;
}
StringC strFormat;
strFormat.Format( L"%%s_%d", nCount );
strName.Format( strFormat, (const wchar_t*)strName.Mid( 0, nMaxChars-nCountDigit-1 ) );
}
public T Find Predicate match
int result = CgPointCollection.Find(
delegate( XmlCgPoint point ) { return point.Name == nameToFind; } );