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

Invalid results when using big numbers #46

Open
nvivant opened this issue Dec 22, 2017 · 3 comments
Open

Invalid results when using big numbers #46

nvivant opened this issue Dec 22, 2017 · 3 comments

Comments

@nvivant
Copy link

nvivant commented Dec 22, 2017

Hello,
Although there's no size limit for entered numbers, the result wrong for big numbers.
3 examples 👍
11111111111111111-1 = 11111111111111112
777777777777777777+1 = 777777777777777792 !
777777777777777777-1 = 777777777777777792 ?!
Tested on elementaryOS Loki with various kernels (4.4.0-104-generic and 4.13.10-041310-generic)
[INFO 14:26:07.508519] Application.vala:154: Calculatrice version: 0.1.3


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@LorkScorguar
Copy link

I also have this issue on latest calculator app. It seems that most calculator apps have this issue, even Google.
15 numbers is the max precision we can get

@michallepicki
Copy link

Recently Microsoft open-sourced their calcuator app, and inside we can find a library that allows for

infinite precision for basic operations (addition, subtraction, multiplication, division) and 32 digits of precision for advanced operations (square root, transcendental operators)

The calculator is written in C++ but glancing over the library I think it's using only C so it should be possible to use it relatively easily.

@ghost
Copy link

ghost commented Mar 12, 2019

Another example:
12345679 * 12345679 * 81 = 12345678987654320, but it was expected 12345678987654321.

The problem is that the built-in data type, double, is used for calculations. The built-in types are good for software calculations like iterations over the transition matrix, when a range of values ​​is known. But to use them for working with user data, when the range is obviously unknown and accuracy is important at the output, is bad practice.

The solution is quite simple: use third-party data types for calculations using long arithmetic.
Like MPRF (Examples of good calculators you can see there in "Software Using MPFR")

https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software

For Vala there is a building to libgcrypt: https://gitlab.gnome.org/GNOME/vala-extra-vapis/blob/master/gcrypt.vapi
See MPI

Or see https://github.com/GNOME/gnome-calculator/tree/master/vapi

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

4 participants