Silverfrost Forums

Welcome to our forums

action of acos/asin intrinsic functions

5 Jun 2008 9:15 #3302

I recently wrote some code which used the Fortran intrinsic function ACOS. The argument of course must lie between -1.0 and 1.0 for any meaningful result. My example code computed a value for the argument which was -1.0 except at the 15th decimal place, but FTN95 still raised a run time error due to an argument outwith the allowed range

My request is for the FTN95 versions of ACOS/ASIN to behave more like Linux/Unix versions, i.e. if the number is -1 or +1 within a certain (generous) tolerance, it be treated as exactly -1 or + 1

Over the years I have found many examples where this behaviour has necessitated writing extra code to ensure arguments don't fall outwith the allowed range. This code is not necessary when using most Linux/Unix Fortran compilers !

5 Jun 2008 9:56 #3303

Louis, isn't it best practice to write code that checks these arguments as a matter of course, and aren't the Linux/Unix compilers actually breaking the standard ?

5 Jun 2008 11:00 #3304

Hi,

John is absolutely right. You could try the real*10 precision in calculations leading up to your ACOS/ASIN, or if you are not interested in the checks then how about a lazy ACOS/ASIN, typically:

angle=acos(max(-1d0,min(1d0,cos_of_angle)))

Regards

Ian

5 Jun 2008 11:22 #3305

Hello

I agree in principle with the comments of John & Ian that the code should be in itself robust (rather than relying on compiler user-friendliness). In fact I use exactly the quick fix that Ian suggested.

Its just that the code I write is compiled both for Windows with FTN95 and for Linux, and I constantly find these little issues. A bigger issue is the Unix 'nan' as an escape from e.g. zero divide and similar errors.

In the end though FTN95 is a truly excellent tool at winkling out coding errors...

Regards Louis

Please login to reply.