Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finite precision problems #15

Open
rafabap opened this issue Apr 3, 2017 · 3 comments
Open

Finite precision problems #15

rafabap opened this issue Apr 3, 2017 · 3 comments

Comments

@rafabap
Copy link

rafabap commented Apr 3, 2017

In the stress testing model we have started to encounter problems due to finite precision, since we use double for the value of all contracts and as the unit of cash.

We run into problems whenever we perform comparisons, due to the accumulated errors from adding and subtracting quantities.

At the moment the most sensible solution would seem to be using int for the value of everything. Any better suggestions welcome!

@rafabap
Copy link
Author

rafabap commented Apr 3, 2017

@davidrpugh I was wondering whether you could help? The only solutions I can come up with are switching to int, using some Java class that deals with rounding errors such as BigDecimal (which in practice, is equivalent to using integer arithmetic) or guarding against the final precision inside all comparisons in the code (especially when comparing against zero). Do you know if there is a good standard solution to these problems?

@davidrpugh
Copy link
Member

@rafabap I have encountered exactly the same issue in the auctions library and in agora. @bherd-rb and I discussed this at length and settled on using Long in all of our calculations. Using BigDecimal would entail taking a significant performance hit. @DavoudTaghawiNejad might have thoughts on this...

@davidrpugh
Copy link
Member

@rafabap Came across this link which has suggestions for performing efficient financial calculations...

http://java-performance.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants