- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can anyone tell me where I can find out the range of valid numbers for trig functions? I am having problems with SINH computations.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want sinh(x) then you must have
abs(x)
otherwise it'll overflow.
HTH,
Gerry T.
abs(x)
otherwise it'll overflow.
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want the sinh(x) then you must have
abs(x)
otherwise it'll overflow.
HTH,
Gerry T.
abs(x)
otherwise it'll overflow.
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for the confusion, huge should read 2*huge, I think,:-).
Ciao,
Gerry T.
Ciao,
Gerry T.
![](/skins/images/DF2E495CEC88D713A66401CF495CD875/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page