FossifyOrg / Calculator

A calculator for quick simple calculations with a nice user interface and no ads

Home Page:https://www.fossify.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accuracy loss due to limited data type

Aga-C opened this issue · comments

Checklist

  • I can reproduce the bug with the latest version.
  • I made sure that there are no existing issues - open or closed - to which I could contribute my information to.
  • I have read the FAQ and my problem isn't listed.
  • I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
  • This issue contains only one bug.
  • I have read and understood the contribution guidelines.

Describe the bug
App relies on exp4j to perform calculations, which is based on Double data type. It's a floating-point data type, which causes accuracy loss, especially with very long inputs.

I see two possible solutions:

  1. Stop relying on exp4j for calculations (especially that app doesn't utilize its most powerful feature - preserving operation order) and rewrite the app to use BigDecimal instead Double.
  2. Add validation to input, which would stop users from inputting numbers too large to be handled by Double type. However, it won't guarantee that user won't run in the same problem during calculations.

To Reproduce
Steps to reproduce the behavior:

  1. Open the app.
  2. Tap any digit (despite 0) circa 20 times.

Result: At some point, instead of the digit I input, 0 is added.

Another case:

  1. Open the app.
  2. Tap decimal separator and then 9 over 13 times.

Result: At some point, the integer part of the number starts incrementing by one with each new decimal digit.

Expected behavior
I should see the number I've typed.

Device info (please complete the following information):

  • Model: OnePlus 9 Pro
  • OS: Android 13
  • Version Simple Calculator 5.12.0