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

Fix calculator search precision and rounding errors #4796

Merged
merged 4 commits into from
Sep 14, 2024

Conversation

tgex0
Copy link
Contributor

@tgex0 tgex0 commented Sep 11, 2024

Description

Fixes calculator search result precision and rounding errors.

Previously:

  • pi*0 = 0E-15
  • pi*1.000 = 3.141592653589793000
  • 2.0*6.0 = 6.00
  • 1/3*3 = 0.9999999999999999

This PR fixes such issues, now resulting in:

  • pi*0 = 0
  • pi*1.000 = 3.141592653589793
  • 2.0*6.0 = 6
  • 1/3*3 = 1

Fixes #4756

Type of change

❌ General change (non-breaking change that doesn't fit the below categories like copyediting)
✅ Bug fix (non-breaking change which fixes an issue)
❌ New feature (non-breaking change which adds functionality)
❌ Breaking change (fix or feature that would cause existing functionality to not work as expected)

@tgex0 tgex0 marked this pull request as draft September 11, 2024 13:19
@tgex0
Copy link
Contributor Author

tgex0 commented Sep 11, 2024

I changed this PR to a draft to fix a further problem that was revealed by my initial fix.

a527e91 was added to ensure that the equation displayed in the search result tile always reflects the actual search typed in by the user.

The content of the tile (the result and the equation) is only updated if the result or the id changes. (The id uses the result so if the result does not change, the id will not change either.)
Previously, if a user typed in 3*1.0 and then added another zero, the result would change (to 3.100) so the tile was updated and the problem was not evident.

After my initial commit 41ab80a, the result no longer shows insignificant trailing zeros so the result does not change (from 3*1.0 to 3*1.00, for example) and, thus, the tile is not updated if the user adds insignificant zeros to the search.

If the user were to type in 3*1.00001, the equation in the tile would not be updated with all the zeros until the final 1 was entered.

Without changing the logic of when the tile should be updated, the easiest solution is to change the id (with a random value on each search input change), as the result itself cannot be changed.

@tgex0 tgex0 marked this pull request as ready for review September 11, 2024 14:08
@Goooler Goooler enabled auto-merge (squash) September 14, 2024 01:30
@Goooler Goooler merged commit feac7a5 into LawnchairLauncher:14-dev Sep 14, 2024
5 checks passed
@tgex0 tgex0 deleted the Calculator_Precision branch September 14, 2024 09:54
nulldrf pushed a commit to nulldrf/lawnchair that referenced this pull request Sep 19, 2024
…r#4796)

* Fix calculator search precision and rounding errors

* Ensure equation is updated in search result tile

* Update lawnchair/src/app/lawnchair/search/algorithms/data/Calculation.kt

---------

Co-authored-by: Zongle Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Rounding/precision errors in calculator search
3 participants