-
Notifications
You must be signed in to change notification settings - Fork 56
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
subtraction of dimensionless quantities produce surprising result #33
Comments
Digging a little further I realize that the problem is mainly with pre-subtraction and pre-addition So , in summary I think this is resolved by adding these operation to the boost units namespace:
|
AMDG
On 10/05/2018 01:07 AM, Alfredo Correa wrote:
In a generic environment one needs to write generic function involving integer integrals.
```
template<class A, class B> auto f(A a, B b){return 1 - a/b;}
```
Feeding `f(1.,2.)` gives `0.5`.
However if one feeds `f(1.*si::meter, 2.*si::meter)` insted one gets `1` and of type `int`.
I can't reproduce this with VS2017. What compiler are you using?
In Christ,
Steven Watanabe
|
In a generic environment one needs to write generic function involving integer integrals.
Feeding
f(1.,2.)
gives0.5
.However if one feeds
f(1.*si::meter, 2.*si::meter)
insted one gets1
and of typeint
.This is probably because the dimensionless quantities are implicitly convertible to their value type, which is a good feature. But for some reason in this case this
double
is converted to anint
before doing the subtraction. The second implicit conversion in seems to be very strong in the language and I don't see a way to solve this in the library (please don't make the conversionexplicit
! that creates many other problems.).The only solution I found was to define a family of functions specialized for
int
.The good news is that this is in principle only needed for int, the bad news is that one need to implement many functions,
(int - dimlessQ)
,(dimlessQ - int)
,(int + dimlessQ)
,(dimlessQ + int)
,(int * dimlessQ)
,(dimlessQ * int)
,(int / dimlessQ)
,(dimlessQ / int)
.I would say this is a bug, but that can be controversial. What it is not controversial is that it is surpring because even for totally dimensinless arguments it will not behave like a
double
.Is there a workaround solution?
The text was updated successfully, but these errors were encountered: