Is there an implicit type promotion in “float = float - float”?Implicit type conversion rules in C++ operatorsImplicit type conversion in CHow is float variable auto-promoted to double type?What are POD types in C++?Do the parentheses after the type name make a difference with new?Writing containers that can handle implicit sharing, but turn it off for non-copyable types (like unique_ptr)?Implicit conversion in C++C++ Member variables confusionImplicit conversion of both operands for operator==C++ modulus operator with float using #define and own classImplicit conversion to float using avr-gcc: uint8_t vs. uint16_tReusing a float buffer for doubles without undefined behaviourWhen does implicit type conversion occur in C++?
What does air vanishing on contact sound like?
Hang 20lb projector screen on Hardieplank
Password expiration with Password manager
Was Hulk present at this event?
What are the spoon bit of a spoon and fork bit of a fork called?
How to reply this mail from potential PhD professor?
What is the most remote airport from the center of the city it supposedly serves?
Entropy as a function of temperature: is temperature well defined?
Is this homebrew race based on the Draco Volans lizard species balanced?
Unidentified items in bicycle tube repair kit
How can I close a gap between my fence and my neighbor's that's on his side of the property line?
Historically, were women trained for obligatory wars? Or did they serve some other military function?
What word means "to make something obsolete"?
Binary Numbers Magic Trick
Power LED from 3.3V Power Pin without Resistor
Who died in the Game of Thrones episode, "The Long Night"?
Disabling Resource Governor in SQL Server
I caught several of my students plagiarizing. Could it be my fault as a teacher?
Is balancing necessary on a full-wheel change?
What happened to Ghost?
Why was Germany not as successful as other Europeans in establishing overseas colonies?
How do I tell my manager that his code review comment is wrong?
Floor tile layout process?
Write to EXCEL from SQL DB using VBA script
Is there an implicit type promotion in “float = float - float”?
Implicit type conversion rules in C++ operatorsImplicit type conversion in CHow is float variable auto-promoted to double type?What are POD types in C++?Do the parentheses after the type name make a difference with new?Writing containers that can handle implicit sharing, but turn it off for non-copyable types (like unique_ptr)?Implicit conversion in C++C++ Member variables confusionImplicit conversion of both operands for operator==C++ modulus operator with float using #define and own classImplicit conversion to float using avr-gcc: uint8_t vs. uint16_tReusing a float buffer for doubles without undefined behaviourWhen does implicit type conversion occur in C++?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:
float a = foo();
float b = bar();
float c = a - b;
As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?
c++ language-lawyer qa-c
|
show 8 more comments
We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:
float a = foo();
float b = bar();
float c = a - b;
As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?
c++ language-lawyer qa-c
13
Would you mind adding the exact error that it gives you?
– Max Langhof
Apr 26 at 7:49
1
Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.
– Bob__
Apr 26 at 8:19
3
@Damon that's a non-sequitur;shortis promoted tointin this case and yet it makes sense to haveshort
– M.M
Apr 26 at 12:06
3
@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).
– M.M
Apr 26 at 12:31
2
Please provide the actual error message and actual code that produces that error message.
– Yakk - Adam Nevraumont
Apr 26 at 13:54
|
show 8 more comments
We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:
float a = foo();
float b = bar();
float c = a - b;
As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?
c++ language-lawyer qa-c
We are using QA-C for MISRA C++ conformance, but the tool spews out an error for code like this:
float a = foo();
float b = bar();
float c = a - b;
As far as I understand, this has no implicit type promotion as everything will happen in float-sized chunks, but the tool tells me that the subtraction causes one. Is there any situation where there might be implicit promotion?
c++ language-lawyer qa-c
c++ language-lawyer qa-c
asked Apr 26 at 7:45
Ken Y-NKen Y-N
7,996134776
7,996134776
13
Would you mind adding the exact error that it gives you?
– Max Langhof
Apr 26 at 7:49
1
Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.
– Bob__
Apr 26 at 8:19
3
@Damon that's a non-sequitur;shortis promoted tointin this case and yet it makes sense to haveshort
– M.M
Apr 26 at 12:06
3
@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).
– M.M
Apr 26 at 12:31
2
Please provide the actual error message and actual code that produces that error message.
– Yakk - Adam Nevraumont
Apr 26 at 13:54
|
show 8 more comments
13
Would you mind adding the exact error that it gives you?
– Max Langhof
Apr 26 at 7:49
1
Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.
– Bob__
Apr 26 at 8:19
3
@Damon that's a non-sequitur;shortis promoted tointin this case and yet it makes sense to haveshort
– M.M
Apr 26 at 12:06
3
@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).
– M.M
Apr 26 at 12:31
2
Please provide the actual error message and actual code that produces that error message.
– Yakk - Adam Nevraumont
Apr 26 at 13:54
13
13
Would you mind adding the exact error that it gives you?
– Max Langhof
Apr 26 at 7:49
Would you mind adding the exact error that it gives you?
– Max Langhof
Apr 26 at 7:49
1
1
Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.
– Bob__
Apr 26 at 8:19
Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.
– Bob__
Apr 26 at 8:19
3
3
@Damon that's a non-sequitur;
short is promoted to int in this case and yet it makes sense to have short– M.M
Apr 26 at 12:06
@Damon that's a non-sequitur;
short is promoted to int in this case and yet it makes sense to have short– M.M
Apr 26 at 12:06
3
3
@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).
– M.M
Apr 26 at 12:31
@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).
– M.M
Apr 26 at 12:31
2
2
Please provide the actual error message and actual code that produces that error message.
– Yakk - Adam Nevraumont
Apr 26 at 13:54
Please provide the actual error message and actual code that produces that error message.
– Yakk - Adam Nevraumont
Apr 26 at 13:54
|
show 8 more comments
1 Answer
1
active
oldest
votes
There is no implicit promotion involved here.
When conversions involving binary operators are involved, they are called usual arithmetic conversions.
From C++ standard, [expr]/11:
11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
...
(11.4) — Otherwise, if either operand isfloat, the other shall be converted tofloat.
Since both operands are float in your example, there is no such conversion or promotion.
So this could be a false positive from the tool.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55863031%2fis-there-an-implicit-type-promotion-in-float-float-float%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is no implicit promotion involved here.
When conversions involving binary operators are involved, they are called usual arithmetic conversions.
From C++ standard, [expr]/11:
11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
...
(11.4) — Otherwise, if either operand isfloat, the other shall be converted tofloat.
Since both operands are float in your example, there is no such conversion or promotion.
So this could be a false positive from the tool.
add a comment |
There is no implicit promotion involved here.
When conversions involving binary operators are involved, they are called usual arithmetic conversions.
From C++ standard, [expr]/11:
11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
...
(11.4) — Otherwise, if either operand isfloat, the other shall be converted tofloat.
Since both operands are float in your example, there is no such conversion or promotion.
So this could be a false positive from the tool.
add a comment |
There is no implicit promotion involved here.
When conversions involving binary operators are involved, they are called usual arithmetic conversions.
From C++ standard, [expr]/11:
11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
...
(11.4) — Otherwise, if either operand isfloat, the other shall be converted tofloat.
Since both operands are float in your example, there is no such conversion or promotion.
So this could be a false positive from the tool.
There is no implicit promotion involved here.
When conversions involving binary operators are involved, they are called usual arithmetic conversions.
From C++ standard, [expr]/11:
11 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield
result types in a similar way. The purpose is to yield a common type, which is also the type of the result.
This pattern is called the usual arithmetic conversions, which are defined as follows:
...
(11.4) — Otherwise, if either operand isfloat, the other shall be converted tofloat.
Since both operands are float in your example, there is no such conversion or promotion.
So this could be a false positive from the tool.
edited Apr 26 at 8:01
answered Apr 26 at 7:52
P.WP.W
19.6k41961
19.6k41961
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55863031%2fis-there-an-implicit-type-promotion-in-float-float-float%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
13
Would you mind adding the exact error that it gives you?
– Max Langhof
Apr 26 at 7:49
1
Consider also this Q&A, maybe, maybe the tool you are using is misinterpreting what's stated in the second part of that answer.
– Bob__
Apr 26 at 8:19
3
@Damon that's a non-sequitur;
shortis promoted tointin this case and yet it makes sense to haveshort– M.M
Apr 26 at 12:06
3
@Damon you already quoted the text that says "integral promotion shall be performed on both" (not "is allowed to happen" or whatever).
– M.M
Apr 26 at 12:31
2
Please provide the actual error message and actual code that produces that error message.
– Yakk - Adam Nevraumont
Apr 26 at 13:54