-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Clarify behavior of Quantity arithmetic on shifted units #95
Comments
Note: see https://rechneronline.de/temperatur/temperature.php for example of operations on temperatures. Even if the above proposal is not apply, at least we should add tests making sure that 20°C + 10°C = 303.15°C, not 30°C, unless we clearly state in the javadoc a policy about when quantities are considered increments. |
This sounds rather intrusive for adding it to the API and introduce something like Beside |
I never proposed to have a method returning Quantity in The other example is not Yes, addition of an The situation is not comparable to |
The wording sounded a bit like the interface would be expected as a return value. Nevertheless if there were two methods there it had a rather significant impact on the Spec and other places to clarify how to use them and when. It is a bit like the new Similar to CDI 2 I would probably call such new method While |
Wonder, if someone from the SmartHome team like @htreu or @kaikreuzer might help with that at least as Contributors? |
I'm find with Introducing an explicit
|
While it adds extra methods that may actually be less intrusive and complex. #96 asked about possibly adding a few methods now in Let's do a quick vote. |
A) Add a new |
B) Reuse |
I hope others will also cast their vote. I voted B also because the whole formatting topic for quantities would get even more complicated if we had to differentiate between |
Before to vote, is the problem clear to everyone? The mathematical problem (regardless any programmatic API), whether For example is it clearly understood that while C) Leave all types and method signatures as today, and add the following method in
Where |
I know it's a little messy now, but I could update your comment and created an option C there. |
Note: an example of a legitimate use for T₁ + T₂ would be the calculation of the average over a set of temperatures (e.g. (T₁ + T₂)/2), but in that case, the offset is eliminated again by the division. |
Thanks, guess that speaks for sticking to |
Actually, I'd rather opt for 20°C + 10°C = 303.15°C sounds very counter-intuitive. I'm pretty sure this is going to produce a lot of bug reports. Furthermore, I remember from thermodynamics back at university (a quarter of a century ago…) that temperature calculations were done in Kelvin, and nothing else. Not sure for physics, but I seem to remember that there too, you did the conversion into Kelvin when dealing with absolute temperatures. I wonder whether we really have a problem for density sigma-t too, but the oceanographer would have to answer that. Complicating factor: for integer quantity types, 20°C + 10°C will be 303°C, right? |
I morphed your comment into option D. I take @filipvanlaenen D was your choice then?;-) @unitsofmeasurement/experts and @unitsofmeasurement/contributors please consider voting on the three options, we have two thumbs up on the initial text, but that is not clear whether you prefer Option A, B or C to accomplish it. |
@desruisseaux Would it be possible to vote on a choice (A-D) as well, since you presented 3 of them? Thanks, |
Yes, calculation in thermodynamic must be done in Kelvin. This is why 20°C + 10°C = 303.15°C if neither 20°C or 10°C are interval. Maybe 20°C + 10°C = 576.3 K would be less confusing. Option D (no API change) would require that we choose a behavior for I would go for a A amended by C. I.e. do everything described in A, except that the
|
Isn't too early for vote? I'm not sure that we have well explored the proposed plan and alternatives. Each comment is raising new alternatives. |
Well we can't have too many options. I was initially worried, it could better be dealt with in a custom or implementation-specific way. And @filipvanlaenen (or what he proposed as D) seems to share that concern. |
In general, I would vote for D, i.e. do not handle increments at all.
@filipvanlaenen If we do not introduce any increment handling, this would be the correct result, wouldn't it? So if you do not like that, why do you suggest to go for D? |
This is an interesting problem which is the same as for dates (often represented by a duration since January 1st, 1970). You don't add dates together (does not make senses) but you can add a duration to it in order to get a new date: For our temperatures we have: In other words: My choice is therefore D (nothing to do since I believe that it is the default behavior). |
False assumption. |
Just for the full picture: This unit test actually fails, while I think that we all agree that
|
When stating 'is do-able without API change' yesterday, what I meant was, that from the code perspective, no new interfaces or methods would need to be introduced. But I agree, that the behavior and hence associated Java-doc would have to change, which strictly speaking one could also see as a change in API, yes. |
No, the problem is not that we need an extra option for the unit to convert. The target unit (not to be confused with the computational unit) does not matter, as long as the quantities are equivalent as defined in the wiki page. The problem is to know if a quantity is a measurement or a difference (or increment). This is orthogonal with unit. It could be a sub-type of |
That with e.g. some |
To summarize where we are now: this issue was about clarifying arithmetic operations on
|
I don't think this is such a good idea. I would leave things like they are for now, and make the change in one API change instead of two. Also, I'm not so fond of API changes that go completely under the radar, i.e. a change in behaviour without a warning. There may be users out there for which the current implementation works just fine, and then suddenly, they're getting results that don't make much sense, without a compilation error or a runtime exception. As a user, I wouldn't be particularly happy with that. |
In my understanding, the API change - at least for the part standardized by JSR - would have to be done all in one shot, since JSR-385 is about "Unit API 2.0" and must be voted by JCP (Oracle and other members) before to be released. However implementations may have as many releases as they want. So it is possible for Indriya to take a progressive approach if they want, but all Indriya official releases have to be on JSR-363 API as long as JSR-385 has not been officially approved (but Indriya may have development branches on JSR-385 API for testing purpose). JSR-363 API said nothing about the behavior of |
I think it's a good idea to create detail tasks where agreed on. Indriya did not exist until the new JSR was started. And Indriya 1.0 is a fully compatible variation of the Java 8 implementation that was not the RI earlier. It is a bridge to the new RI, actually 1.0 is still using the old "tec." namespace, so after Indriya 1.2 there are package changes, but the general structure is compatible. The only things that are going to change are e.g. |
Closing this after the creation of #130 and unitsofmeasurement/indriya#128 |
@kaikreuzer @htreu it took a while to apply that, but we just finished #130 and thanks to #131 there is a way to calculate e.g. temperatures (with an |
Clarify the behavior of
Q₁ + Q₂
orQ * n
(with n a unitless number) when the unit of measurement ofQ
,Q₁
orQ₂
is "shifted". Example of shifted units are:Taking temperature in °C as an example, addition can happen in at least two different contexts:
In the T₁ + T₂ case, both quantities must be converted to K before addition. So 20°C + 10°C = 303.15°C because T₂ = 283.15 K. In the T + ΔT case, 10°C is an increment (ΔT). So in this later case 20°C + 10°C = 30°C.
In current API, there is no way to know if a number is an absolute quantity or an increment. So there is no way to know if we are in the T₁ + T₂ case or in the T + ΔT case. If we want to differentiate those quantities, we may need to:
UnitConverter
:deltaConvert(double)
, which convert the given value without applying the offset. This is similar todeltaTransform
injava.awt.geom.AffineTransform
.Increment<Q extends Quantity<Q>>
.M₁ + M₂
orM * n
, implementation SHALL do the following steps at least conceptually (implementations are allowed to avoid conversions in some cases provided that the numerical result is the same):Quantity
instances shall be done withUnitConverter.convert(…)
.Increment
instances shall be done withUnitConverter.deltaConvert(…)
.Quantity
+Quantity
=Quantity
Quantity
+Increment
=Quantity
Increment
+Quantity
=Quantity
Increment
+Increment
=Increment
Quantity
* n =Quantity
Increment
* n =Increment
UnitConverter.convert(…)
if the result type isQuantity
.UnitConverter.deltaConvert(…)
if the result type isIncrement
.Requires #98
Requires #99
The text was updated successfully, but these errors were encountered: