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

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

changks888
Principiante
2.532 Visualizações
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 Kudos
1 Solução
Steven_L_Intel1
Funcionário
2.532 Visualizações

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.)

Ver solução na publicação original

6 Respostas
Steven_L_Intel1
Funcionário
2.533 Visualizações

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.)
TimP
Colaborador honorário III
2.532 Visualizações
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.
changks888
Principiante
2.532 Visualizações

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.








Steven_L_Intel1
Funcionário
2.532 Visualizações

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.
Hirchert__Kurt_W
Novo colaborador II
2.532 Visualizações

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


JVanB
Contribuidor valorado II
2.532 Visualizações
DIM(a,b)

Responder