Grasshopper

algorithmic modeling for Rhino

I'm dividing some numbers and I want to filter out all numbers that have an infinite remainder.  For example, if the result of the division is 1.123123123123123~...  I would like to filter it out.  I know how to do the filter, but what I don't know is what condition to put to the filter which will be true if the number is infinite.

Any suggestions?

Views: 481

Replies to This Discussion

Infinite remainder? Floating point values always have a finite remainder because they have a limited number of bits. Do you want to filter out all the non-integers?

I'm trying to filter out all the "infinite" remainders. For example 1/3 will result in .333333333333333 and 1/6 will result in .1666666666666666666, while 1/4 results in .25.

In the above example I would like to filter out the .33333333333333333 and .166666666666666666 because they can never fully resolve. But keep the .25 because it does fully resolve. Sorry if I don't have the nomenclature correct ;)

This will be extremely tricky as there are only about 16 decimal places and the least significant ones will often contain either rounding errors or other digital noise. 0.166666666(repeating) will become 0.16666666667 when properly rounded. 0.25 might become 0.24999999999999999 due to some unintentional rounding. You simply cannot trust decimal numbers in computers. 

You may get 99% of the way there using Horus' solution (round the numbers to -say- 10 or 12 decimal places, then see if the last few digits are zero) but this will always give false positives and false negatives on corner cases.

Are you dividing integers or decimals to generate these numbers?

a rough solution may be considering your infinite number have more than a certain length of digits and cull.

 

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service