- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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.

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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!"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

No, you can't index a function reference.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page