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

[math] add divide #105

Merged
merged 4 commits into from
May 18, 2021
Merged

[math] add divide #105

merged 4 commits into from
May 18, 2021

Conversation

J-N-K
Copy link
Member

@J-N-K J-N-K commented May 16, 2021

This is useful for e.g. to display the remaining time of the dishwasher in minutes instead of seconds. This could also be achieved by multiplying with 0.1666667 but having a dedicated transformation for that is more convenient.

Signed-off-by: Jan N. Klug jan.n.klug@rub.de

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
@J-N-K J-N-K added the enhancement New feature or request label May 16, 2021
@J-N-K J-N-K requested a review from cweitkamp May 16, 2021 14:47
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
@cweitkamp
Copy link
Contributor

Two questions: Should we take care of division by 0? Or handle non-terminating decimal expansion like 1/3? Do we need a unit test for both?

J-N-K added 2 commits May 16, 2021 17:55
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
@J-N-K
Copy link
Member Author

J-N-K commented May 16, 2021

Good point. BigDecimal throws an ArithmeticException for a division by zero, so I decided to catch that in the AbstractMathTransformationService. This also takes care of other errors that could occur in later additions.

Regarding the non terminating expansion: This is a bit difficult, because nobody knows the needed precision. It could be that the transformed value is fed into a Number item and used for other calculations and cutting decimals results in loss of needed precision.

Copy link
Contributor

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the devide() method will throw an ArithmeticException too if there are non terminating decimal issue. Thus we should be in safe haven for now.

@J-N-K J-N-K added this to the 3.1.2 milestone May 18, 2021
@J-N-K J-N-K merged commit a830319 into smarthomej:main May 18, 2021
@J-N-K J-N-K deleted the math-divide branch May 18, 2021 14:29
J-N-K added a commit that referenced this pull request May 18, 2021
* add divide

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
@J-N-K J-N-K changed the title [transform.math] add divide [math] add divide Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants