View Issue Details

IDProjectCategoryView StatusLast Update
0002858FreeCADBugpublic2017-01-22 14:33
Reporterwandererfan Assigned Towmayer  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformall 
Product Version0.17 
Fixed in Version0.17 
Summary0002858: Vector2d Equality Incorrect
DescriptionThe equality operator (==) for Base::Vector2d is incorrect. It uses integer test on floating point operands:

@@ -198,7 +197,8 @@ inline Vector2d& Vector2d::operator= (const Vector2d &rclVct)
 
 inline bool Vector2d::operator== (const Vector2d &rclVct) const
 {
- return (x == rclVct.x) && (y == rclVct.y);
+ return (fabs (x - rclVct.x) <= FLT_EPSILON) &&
+ (fabs (y - rclVct.y) <= FLT_EPSILON);
 }
 
TagsNo tags attached.
FreeCAD Information

Activities

wmayer

2017-01-15 15:31

administrator   ~0007798

> It uses integer test on floating point operands
Why should this be an integer test? It's also valid to check for floating points for equality. However, it's true that for floating point numbers eventual round-off errors should be taken into account.
Now, since Vector2d uses doubles it's better to use DBL_EPSILON for comparison.

Related Changesets

FreeCAD: master 6e7c4915

2017-01-15 16:34:14

wmayer

Details Diff
fixes 0002858: Vector2d Equality Incorrect Affected Issues
0002858
mod - src/Base/Tools2D.h Diff File
mod - src/Base/Vector3D.h Diff File

FreeCAD: master 66b91b1c

2017-01-22 14:33:26

wmayer

Details Diff
partially revert changes of issue 0002858 and add IsEqual method Affected Issues
0002858
mod - src/Base/Tools2D.h Diff File

Issue History

Date Modified Username Field Change
2017-01-15 13:17 wandererfan New Issue
2017-01-15 15:31 wmayer Note Added: 0007798
2017-01-15 15:34 wmayer Changeset attached => FreeCAD Master master 6e7c4915
2017-01-15 15:34 wmayer Assigned To => wmayer
2017-01-15 15:34 wmayer Status new => closed
2017-01-15 15:34 wmayer Resolution open => fixed
2017-01-15 15:35 wmayer Fixed in Version => 0.17
2017-01-22 14:33 wmayer Changeset attached => FreeCAD Master master 66b91b1c