- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Hi all, I confused by the following statement:
max(some_value,0._r8)*j/0
What is the result and its meaning?
thx,
Michael
1 解決策
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.)
コピーされたリンク
6 返答(返信)
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.)
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Quoting - Steve Lionel (Intel)
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.)
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.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Quoting - kchang@uoguelphca
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
