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

## Intel Function Sample

Valued Contributor III
843 Views

I was looking at your function documentation today.

``````
FUNCTION ROOT(A)
X  = 1.0
DO
EX = EXP(X)
EMINX = 1./EX
ROOT  = X - ((EX+EMINX)*.5+COS(X)-A)/((EX-EMINX)*.5-SIN(X))
IF (ABS((X-ROOT)/ROOT) .LT. 1E-6) RETURN
X  = ROOT
END DO
END``````

Unless I am mistaken and I ran it a few times, A > 2 for X to exist.   It just goes in an endless loop with A < 2 and runs into nan, but does not stop.

cosh(x) according to Wikipedia has a minimum of 1 at X = 0 and it increases faster than cos(x) decreases.

``````
FUNCTION ROOT(A)
if(A < 2.000) then
stop  "A has to be greater than 2"
endif
X  = 1.0
DO
EX = EXP(X)
EMINX = 1./EX
ROOT  = X - ((EX+EMINX)*.5+COS(X)-A)/((EX-EMINX)*.5-SIN(X))
IF (ABS((X-ROOT)/ROOT) .LT. 1E-6) RETURN
X  = ROOT
END DO
END``````

Just a thought.

7 Replies
Moderator
775 Views

@JohnNichols, it took some digging, but we found the example you pointed out! I filed a bug report on the Fortran DGR (Developer Guide and Reference), DOC-10256. I added an IF/THEN/ELSE/ENDIF.

Thanks for reporting this.

Valued Contributor III
771 Views

@Barbara_P_Intel , thanks.

I was using the function as a sample and the blasted thing disappeared to infinity and beyond.  So it took a few minutes to track down the problem.  The issue is the interesting shape of the cosh function.

I am sorry I will provide a link in the future.

Moderator
664 Views

A new Fortran Developer Guide and Reference was recently published. The error in the example code is fixed.

The tech writer says, "Thank you for pointing this out!"

Valued Contributor III
564 Views

Barbara:

Thank the tech writer for their kind words.  I showed the comment to my 15 year old daughter and she said even Santa is useful once a year.

She has a way with words, she did not get it from me.

Note this morning on VS 2019 - please upgrade as you only get security fixes.

John

Honored Contributor III
634 Views

Here is the current link to the page in question: FUNCTION . A plot of the function can be viewed using this Wolfram Alpha link.

Honored Contributor III
617 Views

mecej4 (or Steve),

Is there a way for a UDT contained procedure function to be used on the LHS of = that returns a reference to an array as opposed to a scalar? And which subsequently can be indexed;

obj%func(i) = ...

IOW (i) is not an argument to the function but rather is an index into the returned array.

Note, if instead, the function is written to accept the index as an argument and return a reference to a cell within the (hidden) array, this works.

Jim Dempsey

edit:

block

real, pointer :: temp

temp => obj%func

temp(i) = ...

end block

Works, but is not elegant.

Jim

Honored Contributor III
611 Views

No, you can't index a function reference.