1

So, I recently started using the scientific package because it provides arbitrary precision numbers through Data.Scientific which I haven't seen anywhere else. One issue that I've run into is the divergence of division / (which is indeed warned about in the documentation) when property testing my code with QuickCheck. I'm using the Arbitrary instance from quickcheck-instances.

I don't have very much formal (read: none) experience with scientific computing so I was wondering if there is any best practices for handling this case. Is there some decent algorithm for performing this operation with possibly a small loss of precision or some way of detecting this ahead of time and returning Nothing or something equivalent when the result would be ill-defined.

Alternatively, (not as ideal) can I just exclude numbers with infinite decimal expansions from my QuickCheck tests so they don't hang forever? This obviously has the downside that it only treats the symptom and a user of the code could still cause divergence if they passed in "bad" data.

Any suggestions would be greatly appreciated :)

m-renaud
  • 1,275
  • 8
  • 11
  • Could you provide the link to the article where they discuss the problematic issue with the division? I'm interested to take a look in it myself. – Willem Van Onsem Jan 21 '17 at 00:18
  • There wasn't an article that I saw but my understanding is that the conversion from a rational number requires long division which does not terminate on infinitely repeating decimal numbers (https://en.wikipedia.org/wiki/Repeating_decimal#Every_rational_number_is_either_a_terminating_or_repeating_decimal). Looking at the source it's obvious why it diverges, so I was hoping someone knew of an algorithm that did not diverge. There is a `fromRationalRepetend` in the package which may be useful but wanted to see if the problem had been solved already before rolling my own solution. – m-renaud Jan 21 '17 at 00:59

0 Answers0