Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Lengths being evaluated as unequal (when they should be equal)

jacob_kingeryjacob_kingery Member Posts: 39 EDU
To explore transforms (specifically rotations), I've been working on a Feature that takes in a string and performs the corresponding moves on a (crude) Rubik's Cube model.  However, there's something weird going on when I try to isolate the cubies on the back side of the cube.  My strategy is to compare certain dimensions of the cubie bounding boxes to the bounding box of the overall cube, and this works for all other sides.

To debug, I have it print out the values it is comparing, followed by the result of the comparison:
// Cubies on the back
if (isIn(side, ['B', 'b']))
{
    print(bounds.maxY);
    print(' =?= ');
    println(maxCorner[1]);
    println(maxCorner[1] == bounds.maxY);
    if (maxCorner[1] == bounds.maxY) {
        cubies = append(cubies, thisCubie);
    }
}

The results of this are what are confusing to me. Whenever the values are unequal, it prints false as expected. However, when the values appear to be equal (and should be equal), it sometimes evaluates them as unequal and sometimes as equal.
...
0.0203497 meter =?= 0.00637966 meter
false
0.0203497 meter =?= 0.0203497 meter
false
...
0.0203497 meter =?= 0.00637966 meter
false
0.0203497 meter =?= 0.0203497 meter
true
...

Any ideas as to what might be going on? FS version is 255.0 if that could be relevant.

Best Answer

Answers

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    edited January 2016
    We also have a bugfix coming where even slightly unequal values will be printed as different to avoid precisely this confusion.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • jacob_kingeryjacob_kingery Member Posts: 39 EDU
    Ah, thanks.  I was wondering if it could be something along those lines.

    Looking through the standard library, I found various tolerantEquals predicates. Would using those work for catching floating point number issues?

    On a side note, the tolerantEquals predicate in units.fs has a precondition, but the documentation states that predicates may not have preconditions. Is the phrase 'may not have' supposed to mean 'sometimes will not have' or 'are not allowed to have'?
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    Yes, tolerantEquals is designed for this exact thing.

    Regarding preconditions, in this case "may not have" means the documentation is both vague and not correct :smile:  Will fix.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • jacob_kingeryjacob_kingery Member Posts: 39 EDU
    Great, thanks!
Sign In or Register to comment.