Strange Fortran instruction [duplicate] - fortran

This question already has answers here:
Strange label usage for an IF condition in a DO loop [duplicate]
(2 answers)
Closed 7 years ago.
Learning old Fortran77-codes full of "goto-spagetti", I met with the following instruction:
if(condition) label1, label2, label3
where labels are just three numbers. Has anybody any ideas what it means?

Arithmetic if. It goes to
label1 if the expression is negative
label2 if the expression is 0
label3 if the expression is positive.
Caveat: If you use it with floating point expressions, note that a result that should be 0 might be "a small number close to 0" due to rounding errors. This limits the usefulness of the arithmetic if.

Related

A strange output in C++ [duplicate]

This question already has answers here:
Strange numbers when array is not initialized in C++ [duplicate]
(3 answers)
What happens to a declared, uninitialized variable in C? Does it have a value?
(9 answers)
Closed 1 year ago.
I have tried a simple code and found a strange error(wrt me)
it is something like s[10]
now i have put some number of values into this array.t
like s[0]=0;s[1]=1.s[2]=2 and all others are empty.
now i put a for loop to see how it goes and to my surprise after index 2, some random numbers popping up in output and idk why. It should be null and the loop should have exited but here, it gives me some output like 01248766575...
why is it happening? pls do help me if u know

C++ | Boolean Values, which is true? [duplicate]

This question already has answers here:
Does true equal to 1 and false equal to 0? [duplicate]
(2 answers)
Closed 4 years ago.
I recently have been reading a tuition book in C++, the question was under a chapter discussing Boolean operators. The question that confused me was as follows:
Which of the following is true?
A. 1
B. 66
C. .1
D. -1
E. All of the above
The answer itself is E according to the paper however, from a newbie perspective like myself, I assumed that A was the answer as a true value is stored as a 1 whereas a false value was stored as a 0? So why would the answer be all of the above?
Any value that is not equal to zero is considered true. So the answer to the question is E since none of the listed values are zero.

What is the use of // operator in Python and when is it advisable? [duplicate]

This question already has answers here:
What is the difference between '/' and '//' when used for division?
(16 answers)
Closed 6 years ago.
How is it different than "/"?
I tried print 10//5 and print 10/5 and both gave the same result.
Try:
print 10.0/6
print 10.0//6
The first is regular division, which results in a floating-point number, whereas the latter is integer division, which truncates the decimal part.

Fortran IF loop [duplicate]

This question already has answers here:
Strange label usage for an IF condition in a DO loop [duplicate]
(2 answers)
Closed 9 years ago.
I have a question about some code I'm looking at written in Fortran. The section of the code I'm confused about is written below.
DO 40 LL=1,N
DO 40 I=1,N-1,2
IF((LL-I)*(LL-I-1)*(LL-I*2)*(LL-I+N-2)) 22,21,22
NODO=LL-I+1
IF((LL.EQ.1) .AND. (I.EQ.N-1)) NODO=NODO+N
I don't understand the condition for the first IF statement. It just looks like numbers are being multiplied together but that number isn't checked against anything. Then 3 line numbers are written after the IF statement. Do anyone know what this IF statement is doing? The last IF statement makes sense as a condition is actually being checked. Thanks.
The line
IF((LL-I)*(LL-I-1)*(LL-I*2)*(LL-I+N-2)) 22,21,22
is an arithmetic if statement, which is certainly obsolescent (the Fortran standard term for deprecated) and may even have been removed in the latest language standard(s). If the condition evaluates to a negative number program control branches to the line with the first label (ie 22), if it evaluates to 0 to the second label (21), if to a positive value to the third label (22). As you see the three labels need not all be different.

Meaning of a comma in a number [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C++ Comma Operator
that probably a trivial question, but I don't know the answer. And this has been troubling me this afternoon.
I was just writing a function to convert RVB to YUV. Nothing really special, but mistakenly used the comma (,) instead of a dot in my numbers.
It compiles but the result was not what I expected, for example "-3713796" instead of a 0-255 range number.
(0,615*(double) 61) - (0,51498*(double) 61) - (0,10001*(double) 61)
So what does it mean ?
If it's not a compilation error, it's probably usefull for something but what?
Ps: I was using C++ with Qt.
You've accidentally used the comma operator. It evaluates its first operand and discards the result, and then evaluates the second operand and returns its value and type.
In my experience, it's most commonly used in loop statements. For other uses, see Uses of C comma operator
It's the comma operator which evaluates each operand and returns the rightmost. In this case it evaluated 0, then 615*(double) 61 and resulted in a value of that product.