Showing posts with label vav.vn. Show all posts
Showing posts with label vav.vn. Show all posts

Tuesday, March 23, 2010

Do NOT check floats for equality




Don't check floats for equality; check for greater than or less than (EqualityFloatLeft.rule)


Description:
This rule checks whether you check floats for equality instead of checking for greater than or less than.

Benefits:

If you check floats for equality, you make your code more susceptible to rounding errors.

Example:

void func(float a, int b)
{
   if (a==b) { }     // Violation

   while (a!=b) { }  // Violation
}



Repair:

void func(float a, int b)
{
   if (a>=b) { }     // OK

   while (a<=b) { }  // OK
}

Author
ParaSoft


My comment for repairing:

void func(const float a, const int b)
{
    if ( a > b ) { }
    else if ( a < b ) {}
    else {}
    // while (a > b) { };
    // while (a < b) { };
}

Ref: http://www.c-faq.com/fp/fpequal.html
Tags: vav.vn, vav, float, float equality, check float values equality, floating point, absolute, epsilon






Friday, March 12, 2010

vav.vn registered


New address were born in March, 12, 2010. This is vav.vn.
Some suggestions are:
+ v^v
+ vAv
+ vav
+ VaV
+ Viet AntiVirus
+ viet antivirus
+ viet anti-virus
+ Viet anti-virus
+ Viet Anti-Virus
+ Viet AntiVirus
+ < new ideas welcomed>


Labels