Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 토론

the meaning of max(some_value,0._r8)*j/0

changks888
초급자
2,538 조회수
Hi all, I confused by the following statement:

max(some_value,0._r8)*j/0

What is the result and its meaning?

thx,
Michael
0 포인트
1 솔루션
Steven_L_Intel1
2,538 조회수

Well, the result of this would probably be a NaN (Not a Number), since dividing by zero is undefined. the 0._r8 means a real value of 0 with the real kind defined by the parameter constant r8, whatever that happens to be. The result of max(some_value,0._r8) is either 0 or some_value, whichever is larger. That is then multiplied by variable j and divided by zero (or multiplied by j/0 - either meaning is acceptable though both are undefined.)

원본 게시물의 솔루션 보기

0 포인트
6 응답
Steven_L_Intel1
2,539 조회수

Well, the result of this would probably be a NaN (Not a Number), since dividing by zero is undefined. the 0._r8 means a real value of 0 with the real kind defined by the parameter constant r8, whatever that happens to be. The result of max(some_value,0._r8) is either 0 or some_value, whichever is larger. That is then multiplied by variable j and divided by zero (or multiplied by j/0 - either meaning is acceptable though both are undefined.)
0 포인트
TimP
명예로운 기여자 III
2,538 조회수
meaningless, without context. I'd even suspect a typo. Some codes have had O and 0 mixups for decades, tending to disprove any claim to QA checking.
0 포인트
changks888
초급자
2,538 조회수

Well, the result of this would probably be a NaN (Not a Number), since dividing by zero is undefined. the 0._r8 means a real value of 0 with the real kind defined by the parameter constant r8, whatever that happens to be. The result of max(some_value,0._r8) is either 0 or some_value, whichever is larger. That is then multiplied by variable j and divided by zero (or multiplied by j/0 - either meaning is acceptable though both are undefined.)
Hi Steve,
I'm dealing with some climatic modeling. I have a controller to change the calculation. Let's say the controller is defined as "psn" and "psn" can be 1 or 0 depends on the input file.a, b, c and d will be calculated from the other equations.

--- example 1 ---
ans_1 = max(a-b,0._r8)*c/(a+2.*b)*psn + c*(1.-c3psn)

if psn = 1, then
ans_1 =max(a-b,0._r8)*c/(a+2.*b)

if psn = 0, then
ans_1 = max(a-b,0._r8)*c/(a+2.*b)*psn + c
--- end of example 1 ---

--- example 2 ---
ans_2 = a * ((b -c)/(b+d))*psn + a*(1.-psn)

if psn = 1, then
ans_2 = a * ((b -c)/(b+d))

if psn = 0, then
ans_2 = a * ((b -c)/(b+d))*psn + a
--- end of example 2 ---


If that is the case, how can I make it works? Do you have good advice? These code was wrote under Compaq Fortran Compiler. I'm not sure I have to rewrite all of formulas... (that will be very painful!!)

Thank you Steve.








0 포인트
Steven_L_Intel1
2,538 조회수

If it compiled with Compaq Visual Fortran, it should compile with Intel Visual Fortran. I don't know your application or its algorithms, so I can't tell you what to do. I will comment that expressions such as

max(a-b,0._r8)*c/(a+2.*b)*psn + c

could certainly be a problem if psn was zero and the compiler chose to interpret this as:

max(a-b,0._r8)*(c/((a+2.*b)*psn)) + c

Perhaps what is meant instead is:

max(a-b,0._r8)*c/(a+2.*b)*(psn + c)

which would do the add before the multiply. Again, I don't know your application so can't promise that this is the correct interpretation. In a Fortran expression, multiplication and division have "higher precedence" than addition and subtraction and, in the absence of parentheses to direct otherwise, are done first. The compiler can choose to do the multiply and divide in either order.

First, understand what the basis of the expression is and then you can determine how to correctly write it in Fortran.
0 포인트
Hirchert__Kurt_W
새로운 기여자 II
2,538 조회수

Hi Steve,
I'm dealing with some climatic modeling. I have a controller to change the calculation. Let's say the controller is defined as "psn" and "psn" can be 1 or 0 depends on the input file.a, b, c and d will be calculated from the other equations.

--- example 1 ---
ans_1 = max(a-b,0._r8)*c/(a+2.*b)*psn + c*(1.-c3psn)

if psn = 1, then
ans_1 =max(a-b,0._r8)*c/(a+2.*b)

if psn = 0, then
ans_1 = max(a-b,0._r8)*c/(a+2.*b)*psn + c
--- end of example 1 ---


You appear to be incorrectly parsing the expression.

ans_1 = max(a-b,0._r8)*c/(a+2.*b)*psn + c*(1.-psn)

is equivalent to

ans_1 = (max(a-b,0._r8)*c/(a+2.*b))*psn + c*(1.-psn)

not

ans_1 = max(a-b,0._r8)*c/((a+2.*b)*psn) + c*(1.-psn)

so when psn = 0, ans_1 = c.

-Kurt


0 포인트
JVanB
소중한 기여자 II
2,538 조회수
DIM(a,b)

0 포인트
응답