in Education by
Is it considered "bad style" to use the increment operator (++) on floats? It compiles just fine but I find it smelly and counter-intuitive. The question: In what cases is using ++ on float variable justified and better than += 1.0f? If there are no use cases, is there a respectable C++ style guide that explicitly says that ++ on float is evil? For float ++ does not increment by the smallest possble value, but by 1.0. 1.0f has no special meaning (unlike integer 1). It may confuse the reader causing him to think that the variable is int. For float it is not guaranteed that operator++ changes the argument. For example the following loop is not infinite: float i, j; for (i=0.0, j=1.0; i!=j;i=j++); Consequently doing ++ immediately after -- does not guarantee that the value is unchanged. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
In general ++/-- is not defined for floats, since it's not clear with which value the float should be incremented. So, you may have luck on one system where ++ leads to f += 1.0f but there may be situations where this is not valid. Therefore, for floats, you'll have to provide a specific value. ++/-- is defined as "increment/decrement by 1". Therefore this is applicable to floating point values. However, personally i think, that this can be confusing to someone who isn't aware of this definition (or only applies it to integers), so i would recommend using f += 1.0f.

Related questions

0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 17, 2022 in Education by JackTerrance
0 votes
    when increment operator is used what will be the value of sum, if sum=2 and a=15 Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    when increment operator is used. what will be the value of sum, if sum=2 and a=15 Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
0 votes
    Our core application changed from Python 2.6 to Python 2.7 maybe to Python 3 in later release. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How can I round off b to 16.75 >>> b 16.749999999999999 >>> round(, 2) 16.749999999999999 I tried round function but it doesn't worked. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I need to show a details view based on a selected row in a table. I would like to show which ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I need to show a details view based on a selected row in a table. I would like to show which ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
...