Deviations in _Sinh(double, double); and the related functions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following functions are giving wrong results for some of the inputs on
gcc_ppc compiler with Dinkumware library.
double _Sinh(double, double);
float _FSinh(float, float);
long double _LSinh(long double, long double);
These are declared in <ymath.h> in Dinkumware library.

These functions are supposed to behave as follows
_Sinh(a, b) = sinh(a) * b

But when the value of the the first argument('a') is in between [-0.55, 0)
or (0, 0.55]
I am getting wrong results.
_Sinh(a, b) is returning a value equal to sinh(a), what ever may be the
second argument, for the above range of values.
For zero and values very near to it(like 0.00000013) and other values, I am
getting right results.


Here is the sample code.

#include <ymath.h>
#include <iostream>
#include <cmath>

using namespace std;
void verify(char * comment_string, double actual_value, double
expected_value)
{
	
cout<<comment_string<<"\t\t"<<actual_value<<"\t\t"<<expected_value<<endl;
}

void main()
{
	for(double value = -0.6; (value <= 0.6); value += 0.01)
	{
		cout<<"Angle  : "<<value<<endl;
		verify("_Sinh with second arg as -1.2", 
			_Sinh(value, -1.2), std::sinh(value) * -1.2);
		verify("_Sinh with second arg as -1.0", 
			_Sinh(value, -1.0), std::sinh(value) * -1.0);
		verify("_Sinh with second arg as -0.9", 
			_Sinh(value, -0.9), std::sinh(value) * -0.9);
		verify("_Sinh with second arg as -0.2", 
			_Sinh(value, -0.2), std::sinh(value) * -0.2);
		verify("_Sinh with second arg as 0.0", 
			_Sinh(value, 0.0), std::sinh(value) * 0.0);
		verify("_Sinh with second arg as 0.2", 
			_Sinh(value, 0.2), std::sinh(value) * 0.2);
		verify("_Sinh with second arg as 0.9", 
			_Sinh(value, 0.9), std::sinh(value) * 0.9);
		verify("_Sinh with second arg as 1.0", 
			_Sinh(value, 1.0), std::sinh(value) * 1.0);
		verify("_Sinh with second arg as 1.2", 
			_Sinh(value, 1.2), std::sinh(value) * 1.2);
	}
	verify("_Sinh for a value very near to zero", 
		_Sinh(value, 0.00000013), std::sinh(value) * 0.00000013);
}

Observe that when the values for 'a' for _Sinh(a, b) are in the range [-0.6,
-0.55] the results are correct,
for [-0.55, 0.55] results are wrong(except for zero),
for [0.55, 0.6] the results are correct.
Can you please tell me if my observation is correct and why this is
happening like this.

Thanks,
pavan.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux