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

Valid arguments for trig functions

tmcole
Beginner
411 Views
Can anyone tell me where I can find out the range of valid numbers for trig functions? I am having problems with SINH computations.
0 Kudos
5 Replies
Intel_C_Intel
Employee
411 Views
Couldn't find anything about this myself either.
Just running through a loop in CVF 6.6b, with 4 byte reals it starts producing infinity as a result with inputs 89 and 90, and craps out totally with an error between 710 and 711. If you switch the default reals to 8 bytes, it will keep working after 89, but still
craps out between 710 and 711. I didn't try. For negative arguments, it produces -infinity between -89 and
-90, and craps out between -710 and -711. With 8 byte
reals as default, it works after -90, but still craps out
between -710 and -711. Here's the program. I'm running it in debug configuration. The error it gives is
overflow.

do 100 i=64,1024
x = -i
y = sinh(x)
write(*,*) x,y
100 continue
read(*,*) i
stop
end
0 Kudos
gfthomas8
Novice
411 Views
If you want sinh(x) then you must have

abs(x)
otherwise it'll overflow.

HTH,
Gerry T.
0 Kudos
TimP
Honored Contributor III
411 Views
Careers have been made out of this topic; there is no single simple answer. The ELEFUNT test suite (look up on Google) checks the numerical behavior of an implementation, including picky tests for failures at boundary values.

A "naive" or sloppy version of sinh() would "fail" (e.g. produce Infinity) for the same arguments where exp() would fail, while a correct implementation will not go Infinity until .5*exp(x) must be represented as Infinity. It may not be practical to get the point where it goes Infinity exactly right.


Also, a sloppy version may be inaccurate for small values of x, or even fail. Supposing that x is such that exp(x)==1. Then, if you calculate .5*(exp(x)-exp(-x)), you get 0 when you want x. A correct version will take care of this, by using a different method for x near 0, and matching that expansion correctly to the one for large x, or by basing the calculation on an accurate representation of .5*(exp(x)-1).

There are no invalid arguments, other than NaN, but there are arguments which will produce a result which will likely break your program.

Even when using the x87 built-in intrinsics, it takes about 16 lines of C/asm source to get sinh() right. Certain compilers which expand code in line, using the x87 intrinsics, will skip one or more of the nit-picky precautions, in the expectation that people don't insist on ability to pass all the ELEFUNT tests, or would prefer speed or small generated code size.
0 Kudos
gfthomas8
Novice
411 Views
If you want the sinh(x) then you must have

abs(x)
otherwise it'll overflow.

HTH,
Gerry T.
0 Kudos
gfthomas8
Novice
411 Views
Sorry for the confusion, huge should read 2*huge, I think,:-).

Ciao,
Gerry T.
0 Kudos
Reply