-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
[openhab.core] DecimalType-ctor with Number argument #2596
[openhab.core] DecimalType-ctor with Number argument #2596
Conversation
83102d6
to
53f3766
Compare
Thanks for your contribution. Wouldn't it make more sense to refactor the class to have a generic constructor passing a |
Yes, I am with you. That was actually my first thought. That would also be consistent with the implementation of But I would of course welcome the consistent solution with the |
I would like to go for the We will have feature freezer on next Monday ( 13th or December ) thus I would like to reschedule this change to a later time to make sure we do not introduce unwanted side effects. I hope that is okay for you. |
53f3766
to
9541792
Compare
9541792
to
9f826ff
Compare
Yes of course, its OK for me. I replaced my previous commit with an appropriate one. |
e787de2
to
f1529bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes.
bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DecimalType.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DecimalType.java
Outdated
Show resolved
Hide resolved
@kippAndMost Are you still around to finalize this PR? |
Hi cweitkamp, sorry, I have some work overload at the moment. I will have a look at as soon as possible. |
The expectation is, that when a `DecimalType` was constructed with a `float` value, the precision of its `doubleValue()`, `floatValue()`, `toBigDecimal()` and `toString()` is preserved. But there are `float` values like `4.2f` or `37.1f` that cannot directly converted to `double` without precision loss. This commit replaces all the numerical constructors of `DecimalType` with a single constructor with a `Number` argument, so that all `float` values can be used without precision loss. NOTE: There is some special handling needed for `QuantityType` and `HSBType` because these types has a special none convential `toString` implementation. Signed-off-by: Ringo Frischmann <ringo.frischmann@kiwigrid.com> Co-Authored-By: Christoph Weitkamp <github@christophweitkamp.de>
bcc9d23
to
d4a6112
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
I think this PR has broken the add-ons build, can you have a look at it @kippAndMost? See: https://ci.openhab.org/job/openHAB-Addons/638/
|
This broke Fronius binding:
A fix for Fronius binding has been submitted in a PR. A quick search shows this addon file using the same cast to (double) |
and openweathermap
|
Looks like this is heavily breaking (binary) API compatibility. |
Can't it keep the old constructors as well? |
Did you check if just re-compiling also fixes the problem? I believe this is only incompatible in binary code, not at source level. |
@J-N-K is right. We first should fix the build and release a new snapshot before starting to look into every binding. I hope the only think which I missed in this PR is the |
@cweitkamp But maybe keeping the old constructors is also a good idea to maintain binary compatibility. They can all call a single new one. Maybe mark them as Breaking binary compatibility here would require all add-ons from the Community-Marketplace (and JSON 3rd Party) to be either compatible with 3.2 or 3.3 (there is no versioning). While this can be easily managed for JSON 3rd Party by just providing a different version in another JSON-file, the community marketplace currently can't handle that and would require bigger refactoring of the add-on service and probably an additional flag in Discourse. |
I submitted a PR to fix the build openhab/openhab-addons#12374 You got a point. That is a strong argument. @openhab/core-maintainers Wdyt? Should we reintroduce the removed constructors. |
I think this should be decided before M2. |
This will actually break compatibility with 3.2 for any binding that is compiled against that 3.3 where |
The expectation is, that when a `DecimalType` was constructed with a `float` value, the precision of its `doubleValue()`, `floatValue()`, `toBigDecimal()` and `toString()` is preserved. But there are `float` values like `4.2f` or `37.1f` that cannot directly converted to `double` without precision loss. This commit replaces all the numerical constructors of `DecimalType` with a single constructor with a `Number` argument, so that all `float` values can be used without precision loss. NOTE: There is some special handling needed for `QuantityType` and `HSBType` because these types has a special none convential `toString` implementation. Signed-off-by: Ringo Frischmann <ringo.frischmann@kiwigrid.com> GitOrigin-RevId: 9e721dc
The expectation is, that when a
DecimalType
was constructed with afloat
value, the precision of itsdoubleValue()
,floatValue()
,toBigDecimal()
andtoString()
is preserved. But there arefloat
values like
4.2f
or37.1f
that cannot directly converted todouble
without precision loss.
This commit replaces all the numerical constructors of
DecimalType
with a single constructor with a
Number
argument, so that allfloat
values can be used without precision loss.
NOTE: There is some special handling needed for
QuantityType
andHSBType
because these types have a special none conventionaltoString
implementation.