-
Notifications
You must be signed in to change notification settings - Fork 40
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
Unitless types #106
Comments
You sure |
Hi,
It does get converted to m^2. But if you divide 15m by 15m you should get 1 not 1m^2.
David
From: ypearson ***@***.***
Sent: 11 April 2022 15:01
To: bernedom/SI ***@***.***>
Cc: David Orchard (SXS UK) ***@***.***>; Author ***@***.***>
Subject: Re: [bernedom/SI] Unitless types (Issue #106)
EXTERNAL EMAIL: Remember the 9 Phishing Indicators
You sure a/a doesn't get implicitly converted to 1 m^2 ?
—
Reply to this email directly, view it on GitHub<#106 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYVEJ4C75I3F2VFDW7WX4W3VEQWBJANCNFSM5TDHY33Q>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
…_____________________________________________________________________
Spirax-Sarco Engineering Plc. This e-mail has been scanned for viruses by Cisco Cloud Email Security.
|
Yeah, I agree. However, its the same as this: |
I see what you are getting at:
square_metre_t<float> c1 = 1; // This is not square meters!!!
This does compile. You are saying 1 is a square meter. However, when the value is the result of a computation you are relying on the engineer not making a mistake and messing up his units.
square_metre_t< float > c2 = 1_m2; // This is square meters!!!
square_metre_t< float > c3 = 1; // This is not square meters!!!
using m2 = 1_m2;
float data = 15.0F;
square_metre_t< float > c3 = data * 1_m2; // This is square meters!!!
square_metre_t< float > c4 = data * m2; // Nicer!!!
From: ypearson ***@***.***
Sent: 11 April 2022 15:15
To: bernedom/SI ***@***.***>
Cc: David Orchard (SXS UK) ***@***.***>; Author ***@***.***>
Subject: Re: [bernedom/SI] Unitless types (Issue #106)
EXTERNAL EMAIL: Remember the 9 Phishing Indicators
Yeah, I agree. However, its the same as this:
square_metre_t c = 1
Does the above compile? 1 is unitless too
—
Reply to this email directly, view it on GitHub<#106 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYVEJ4C2U22TIQLEKQNJPJ3VEQXVVANCNFSM5TDHY33Q>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
…_____________________________________________________________________
Spirax-Sarco Engineering Plc. This e-mail has been scanned for viruses by Cisco Cloud Email Security.
|
Maybe one solution is to not allow implicit conversion I'm not the author, but I'm interested in this discussion. |
Hi,
You are right that would be my preferred solution.
David
From: ypearson ***@***.***
Sent: 11 April 2022 16:25
To: bernedom/SI ***@***.***>
Cc: David Orchard (SXS UK) ***@***.***>; Author ***@***.***>
Subject: Re: [bernedom/SI] Unitless types (Issue #106)
EXTERNAL EMAIL: Remember the 9 Phishing Indicators
Maybe one solution is to not allow implicit conversion
Idea:
metre_t d1 = 5; //does not compile
metre_t d2 = 5*1_m; //does compile
I'm not the author, but I'm interested in this discussion.
—
Reply to this email directly, view it on GitHub<#106 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYVEJ4HWZ6LLAH5UBPDBMPTVEQ75RANCNFSM5TDHY33Q>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
…_____________________________________________________________________
Spirax-Sarco Engineering Plc. This e-mail has been scanned for viruses by Cisco Cloud Email Security.
|
As you guessed, this happens because of the implicit conversion.
What happens in the example is that
So if you change the example to use Marking the constructors as |
I solved the issue by marking the constructor that takes a primitive for the units to It is in the following branch: https://github.com/bernedom/SI/tree/feature/no-implicit-conversion-on-assignment-operator Any feedback if the behavior is as expected would be great. |
This will be in release 2.5.0 |
Hi,
If you make the constructor explicit you force the engineer to do:-
float data = 15.0F;
square_metre_t<float> c1 = 1_m;
square_metre_t<float> c1 = square_metre_t<float> { data };
This forces them to be explicit about the units and the following mistake becomes compile time error.
centi_metre_t<> a = 15_cm;
square_metre_t<> c = a / a; // This is not square meters!!!
From: David Orchard (SXS UK)
Sent: 11 April 2022 15:27
To: bernedom/SI ***@***.***>
Subject: RE: [bernedom/SI] Unitless types (Issue #106)
I see what you are getting at:
square_metre_t<float> c1 = 1; // This is not square meters!!!
This does compile. You are saying 1 is a square meter. However, when the value is the result of a computation you are relying on the engineer not making a mistake and messing up his units.
square_metre_t< float > c2 = 1_m2; // This is square meters!!!
square_metre_t< float > c3 = 1; // This is not square meters!!!
using m2 = 1_m2;
float data = 15.0F;
square_metre_t< float > c3 = data * 1_m2; // This is square meters!!!
square_metre_t< float > c4 = data * m2; // Nicer!!!
From: ypearson ***@***.***
Sent: 11 April 2022 15:15
To: bernedom/SI ***@***.******@***.***>>
Cc: David Orchard (SXS UK) ***@***.******@***.***>>; Author ***@***.******@***.***>>
Subject: Re: [bernedom/SI] Unitless types (Issue #106)
EXTERNAL EMAIL: Remember the 9 Phishing Indicators
Yeah, I agree. However, its the same as this:
square_metre_t c = 1
Does the above compile? 1 is unitless too
—
Reply to this email directly, view it on GitHub<#106 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYVEJ4C2U22TIQLEKQNJPJ3VEQXVVANCNFSM5TDHY33Q>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
…_____________________________________________________________________
Spirax-Sarco Engineering Plc. This e-mail has been scanned for viruses by Cisco Cloud Email Security.
|
centi_metre_t a = 15;
square_metre_t c = a / a; // This is not square meters!!!
CHECK_ALMOST_EQUAL(c.value(), 1.0F, 1E-6);
The units of 'c' are not square metres! In fact 'c' does not have units. So why does this compile?
The text was updated successfully, but these errors were encountered: