Trailing-Edge
-
PDP-10 Archives
-
SRI_NIC_PERM_FS_1_19910112
-
c/kcc/bug24.raw
There are no other files named bug24.raw in the archive.
extern float _fltmax, _flteps, _fltmin;
extern double _dblmax, _dbleps, _dblmin;
extern long double _ldbmax, _ldbeps, _ldbmin;
extern double
acos(double), asin(double), atan(double), atan2(double, double),
ceil(double), cos(double), cosh(double), exp(double),
fabs(double), floor(double), fmod(double, double),
frexp(double, int *), ldexp(double, int), log(double),
log10(double), modf(double, double *), pow(double, double),
sin(double), sinh(double), sqrt(double), tan(double), tanh(double);
extern double _sign(), _xmant(), _poly();
extern int _xexp();
extern int errno;
static void d4_5_2();
static void d4_5_3();
static void d4_5_4();
static void d4_5_5();
static void d4_5_6();
/* 4.5 - Mathmatics <math.h>
* This version is not intended to verify the "correctness" of the
* results of the math library, but rather to verify the existence
* of the functions and some domain/range properties.
*/
main()
{
checkthat(41, 33 != 34);
checkthat(42, 33 != 0);
checkthat(43, 34 != 0);
checkthat(44, _dblmax > 0);
d4_5_2();
d4_5_3();
d4_5_4();
d4_5_5();
d4_5_6();
}
/*
* 4.5.2 - Trignometric functions
*/
static void d4_5_2()
{
double pi = acos(-1.);
double dummy;
/* 4.5.2.1 acos
* has domain on [-1,1]
*/
errno = 0; /* return value on the domain errs is implem-def */
dequals( - 64, acos(-1.1), 0.0);
iequals(65, errno, 33);
errno = 0;
dequals( - 67, acos(1.1), 0.0);
iequals(68, errno, 33);
dequals(69, acos(1.), 0.0);
dequals(70, acos(0.), pi/2);
dequals(71, acos(-1.), pi);
dequals(72, acos(cos(pi/4)), pi/4);
/* ERROR at line 72 : (0.7853981629957472428) != (0.7853981633974483095) */
/* ERROR at line 72 : (0.7853981629957472428) != (0.7853981633974483095) */
/* 4.5.2.2 asin
* has domain on [-1,1]
*/
errno = 0;
dequals( - 78, asin(-1.1), 0.0);
iequals(79, errno, 33);
errno = 0;
dequals( - 81, asin(1.1), 0.0);
iequals(82, errno, 33);
dequals(83, asin(1.), pi/2);
dequals(84, asin(0.), 0.0);
dequals(85, asin(-1.), -pi/2);
dequals(86, asin(cos(pi/4)), pi/4);
/* ERROR at line 86 : (0.7853981637991493758) != (0.7853981633974483095) */
/* ERROR at line 86 : (0.7853981637991493758) != (0.7853981633974483095) */
/* 4.5.2.3 atan
* has domain (-HUGE_VAL, HUGE_VAL)
*/
dequals(91, atan(0.0), 0.0);
dequals(92, atan(1.0), pi/4);
/* ERROR at line 92 : (0.7853981637991494407) != (0.7853981633974483095) */
/* ERROR at line 92 : (0.7853981637991494407) != (0.7853981633974483095) */
dequals(93, atan(tan(pi/7)), pi/7);
/* ERROR at line 93 : (0.4487989509145287445) != (0.4487989505128276055) */
/* ERROR at line 93 : (0.4487989509145287445) != (0.4487989505128276055) */
/* 4.5.2.4 atan2
* figures out the correct quadrant
*/
dequals(99, atan2(sin(pi/4), cos(pi/4)), pi/4);
/* ERROR at line 99 : (0.7853981637991494102) != (0.7853981633974483095) */
/* ERROR at line 99 : (0.7853981637991494102) != (0.7853981633974483095) */
dequals(100, atan2(sin(3*pi/4), cos(3*pi/4)), 3*pi/4);
/* ERROR at line 100 : (-0.7853981637991494103) != (2.356194490192344929) */
/* EALGO at line 100 : (-0.7853981637991494103) != (2.356194490192344929) */
dequals(101, atan2(sin(-pi/4), cos(-pi/4)), -pi/4);
/* ERROR at line 101 : (2.356194489790643829) != (-0.7853981633974483095) */
/* EALGO at line 101 : (2.356194489790643829) != (-0.7853981633974483095) */
dequals(102, atan2(sin(-3*pi/4), cos(-3*pi/4)), -3*pi/4);
/* ERROR at line 102 : (-2.356194489790643828) != (-2.356194490192344929) */
/* EPREC at line 102 : (-2.356194489790643828) != (-2.356194490192344929) */
errno = 0;
atan2(0.0, 0.0);
iequals( - 105, errno, 33);
/* 4.5.2.5 cos
* works in radians
*/
dequals(110, cos(0.0), 1.0);
dequals(111, cos(pi/2), 0.0);
dequals(112, cos(pi), -1.0);
dequals(113, cos(3*pi/2), 0.0);
dequals(114, cos(pi/4), cos(-pi/4));
dequals(115, cos(pi/4), sin(pi/4));
/* ERROR at line 115 : (0.7071067811865474787) != (0.707106781186547522) */
/* EPREC at line 115 : (0.7071067811865474787) != (0.707106781186547522) */
/* 4.5.2.6 sin
* works in radians
*/
dequals(120, sin(0.0), 0.0);
dequals(121, sin(pi/2), 1.0);
dequals(122, sin(pi), 0.0);
dequals(123, sin(3*pi/2), -1.0);
dequals(124, sin(pi/2), -sin(-pi/2));
/* 4.5.2.7 tan
* also works on radians
*/
dequals(129, tan(0.0), 0.0);
dequals(130, tan(pi/4), 1.0);
/* ERROR at line 130 : (1.000000000000000061) != (1) */
/* EPREC at line 130 : (1.000000000000000061) != (1) */
dequals(131, tan(-pi/4), -1.0);
/* ERROR at line 131 : (-1.000000000000000061) != (-1) */
/* EPREC at line 131 : (-1.000000000000000061) != (-1) */
}
/*
* 4.5.3 - Hyperbolic functions
*/
static void d4_5_3()
{
double pi = acos(-1.);
/* 4.5.3.1 cosh
* range error returns HUGE_VAL and sets errno
*/
errno = 0;
dequals(157, cosh(_dblmax), _dblmax);
iequals( - 158, errno, 34);
dequals(159, cosh(1.234), cosh(-1.234));
errno = 0;
/* 4.5.3.2 sinh
*/
dequals(164, sinh(_dblmax), _dblmax);
iequals( - 165, errno, 34);
dequals(166, sinh(1.234), -sinh(-1.234));
/* 4.5.3.3 tanh
*/
dequals(170, tanh(1.234), sinh(1.234)/cosh(1.234));
dequals(171, tanh(0.0), 0.0);
dequals(172, tanh(1.234), -tanh(-1.234));
}
/*
* 4.5.4 - Exponential and logrithmic functions
*/
static void d4_5_4()
{
int i;
double dummy;
/* 4.5.4.1 exp
*/
dequals(185, exp(_dblmax), _dblmax);
iequals( - 186, errno, 34);
dequals(187, exp(0.0), 1.0);
dequals(188, exp(-1.1), 1.0/exp(1.1));
/* 4.5.4.2 frexp
*/
dequals(198, frexp(1.234, &i), .617);
iequals(199, i, 1);
dequals(200, frexp(12.34, &i), .77125);
iequals(201, i, 4);
dequals(202, frexp(0.0, &i), 0.0);
iequals(203, i, 0);
/* 4.5.4.3 ldexp
*/
dequals(207, ldexp(3.0, 2), 12.0);
errno = 0;
dequals(209, ldexp(1e37, 32767), _dblmax);
iequals( - 210, errno, 34);
/* 4.5.4.4 log
*/
errno = 0;
dummy = log(-1.0);
iequals(216, errno, 33);
errno = 0;
dequals( - 218, log(0.0), -_dblmax);
iequals( - 219, errno, 34);
dequals(220, exp(log(1.234)), 1.234);
/* 4.5.4.5 log10
*/
errno = 0;
dummy = log10(-1.0);
iequals(226, errno, 33);
errno = 0;
dequals( - 228, log10(0.0), - _dblmax);
iequals( - 229, errno, 34);
dequals(230, log10(1.0), 0.0);
/* ERROR at line 230 : (-5.163483885851243387E-16) != (0) */
/* EALGO at line 230 : (-5.163483885851243387E-16) != (0) */
dequals(231, log10(1.e10), 10.0);
/* 4.5.4.6 modf
*/
dequals(235, modf(12.345, &dummy), .345);
dequals(236, dummy, 12.);
dequals(237, modf(0.0, &dummy), 0.0);
dequals(238, dummy, 0.0);
}
/*
* 4.5.5 - Power functions
*/
static void d4_5_5()
{
double dummy;
/* 4.5.5.1 pow
*/
errno = 0;
dummy = pow(0.0, 0.0);
iequals( - 257, errno, 33);
errno = 0;
dummy = pow(0.0, -1.0);
iequals( - 260, errno, 33);
errno = 0;
dummy = pow(-4.3, 1.1);
iequals(263, errno, 33);
dequals(264, log10(pow(10.0, 1.234)), 1.234);
/* ERROR at line 264 : (1.233999999999999844) != (1.234) */
/* EPREC at line 264 : (1.233999999999999844) != (1.234) */
dequals(265, pow(-3.0, 3.0), -27.0);
/* range errors */
errno = 0;
dequals(269, pow(10.0, _dblmax), _dblmax);
/* ERROR at line 269 : (1) != (1.701411834604692318E+38) */
/* ECHEK at line 269 : (1) != (1.701411834604692318E+38) */
iequals( - 270, errno, 34);
/* ERROR at line -270 : (0) != (34) */
/* ECHEK at line -270 : (0) != (34) */
errno = 0;
/* underflow */
dequals(273, pow(10.0, -_dblmax), 0.0);
/* ERROR at line 273 : (1) != (0) */
/* ECHEK at line 273 : (1.701411834604692318E+38) != (0) */
iequals( - 274, errno, 34);
/* 4.5.5.2 sqrt
*/
errno = 0;
dequals( - 279, sqrt(-1.0), 0.0);
iequals(280, errno, 33);
dequals(281, pow(sqrt(1.234), 2.0), 1.234);
/* ERROR at line 281 : (1.233999999999999478) != (1.234) */
/* EPREC at line 281 : (1.233999999999999478) != (1.234) */
}
/*
* 4.5.6 - Nearest integer, absolute value, and remainder functions
*/
static void d4_5_6()
{
/* 4.5.6.1 ceil
*/
dequals(304, ceil(0.0), 0.0);
dequals(305, ceil(12.345), 13.0);
dequals(306, ceil(-12.345), -12.0);
/* 4.5.6.2 fabs
*/
dequals(310, fabs(12.345), 12.345);
dequals(311, fabs(-12.345), 12.345);
/* 4.5.6.3 floor
*/
dequals(315, floor(0.0), 0.0);
dequals(316, floor(12.345), 12.0);
dequals(317, floor(-12.345), -13.0);
/* 4.5.6.4 fmod
*/
dequals(321, fmod(13.1, 5.0), 3.1);
dequals(322, fmod(-13.1, 5.0), -3.1);
dequals(323, fmod(13.1, -5.0), 3.1);
dequals(324, fmod(-13.1, -5.0), -3.1);
dequals(- 325, fmod(1., 0.), 0.); /* DEC86 */
checkthat(326, fmod(1E38, 1E-38) <= 1E-38); /* DEC86 */
/* ERROR at line 326 */
/* ECHEK at line 326 */
}
static char details[512] = {0};
/*
* CHECKTHAT - simple condition check. If val1 == 0, then
* report an error.
*/
checkthat(line, cond)
int cond;
int line;
{
if (!cond)
{
printf("ERROR at line %d\n", line);
return (0);
}
return (1);
}
/*
* DEQUALS - 'double' equality check. If val1 != val2, then
* report an error. This is computed using an equality approximation
* that verifies that the two numbers are equal to R digits whenever
*
* |x - y| 1 1-R
* ------- <= - 10
* |x| 2
*
* DIGITS_MAX is defined in defs.h
*/
double Delta = 0.0;
dequals(line, val1, val2)
double val1, val2;
int line;
{
double *pd;
if (Delta == 0.0)
Delta = 0.5 / pow(10.0, (18 -1 )-1.0);
if (val1 == val2)
{
return (1);
}
pd = &val1;
if (val1 == 0.0)
pd = &val2;
/* special cases to handle zero against very small numbers */
if (fabs(val1) == 0.0 && fabs(val2) < Delta)
;
else if (fabs(val2) == 0.0 && fabs(val1) < Delta)
;
else if ((fabs(val1 - val2) / fabs(*pd)) > Delta)
{
sprintf(details, ": (%.*G) != (%.*G)",
(18 -1 )+2, val1, (18 -1 )+2, val2);
printf("ERROR at line %d %s\n",line, details);
return (0);
}
return (1);
}
/*
* IEQUALS - 'int' quality check. If val1 != val2, then report an error.
*/
iequals(line, val1, val2)
int val1, val2;
int line;
{
if (val1 != val2)
{
sprintf(details, ": (%d) != (%d)", val1, val2);
printf("ERROR at line %d %s\n",line, details);
return (0);
}
return (1);
}