| 1 |
/* |
| 2 |
Program to test complex divide for correct results on selected values. |
| 3 |
Checking known failure points. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <float.h> |
| 7 |
|
| 8 |
extern void abort (void); |
| 9 |
extern void exit (int); |
| 10 |
|
| 11 |
extern int ilogb (double); |
| 12 |
int match (float _Complex, float _Complex); |
| 13 |
|
| 14 |
#define SMALL FLT_MIN |
| 15 |
#define MAXBIT FLT_MANT_DIG |
| 16 |
#define ERRLIM 6 |
| 17 |
|
| 18 |
/* |
| 19 |
Compare c (computed value) with z (expected value). |
| 20 |
Return 0 if within allowed range. Return 1 if not. |
| 21 |
*/ |
| 22 |
int match (float _Complex c, float _Complex z) |
| 23 |
{ |
| 24 |
float rz, iz, rc, ic; |
| 25 |
float rerr, ierr; |
| 26 |
double rmax; |
| 27 |
int biterr; |
| 28 |
rz = __real__ z; |
| 29 |
iz = __imag__ z; |
| 30 |
rc = __real__ c; |
| 31 |
ic = __imag__ c; |
| 32 |
|
| 33 |
if (__builtin_fabsf (rz) > SMALL) |
| 34 |
{ |
| 35 |
rerr = __builtin_fabsf (rz - rc) / __builtin_fabsf (rz); |
| 36 |
} |
| 37 |
else if (__builtin_fabsf (rz) == 0.0) |
| 38 |
{ |
| 39 |
rerr = __builtin_fabsf (rc); |
| 40 |
} |
| 41 |
else |
| 42 |
{ |
| 43 |
rerr = __builtin_fabsf (rz - rc) / SMALL; |
| 44 |
} |
| 45 |
|
| 46 |
if (__builtin_fabsf (iz) > SMALL) |
| 47 |
{ |
| 48 |
ierr = __builtin_fabsf (iz - ic) / __builtin_fabsf (iz); |
| 49 |
} |
| 50 |
else if (__builtin_fabsf (iz) == 0.0) |
| 51 |
{ |
| 52 |
ierr = __builtin_fabsf (ic); |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
ierr = __builtin_fabsf (iz - ic) / SMALL; |
| 57 |
} |
| 58 |
rmax = __builtin_fmax (rerr, ierr); |
| 59 |
biterr = 0; |
| 60 |
if ( rmax != 0.0) |
| 61 |
{ |
| 62 |
biterr = ilogb (rmax) + MAXBIT + 1; |
| 63 |
} |
| 64 |
|
| 65 |
if (biterr >= ERRLIM) |
| 66 |
return 0; |
| 67 |
else |
| 68 |
return 1; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
int main(int argc, char** argv) |
| 73 |
{ |
| 74 |
float _Complex a,b,c,z; |
| 75 |
float xr[4], xi[4], yr[4], yi[4], zr[4], zi[4]; |
| 76 |
float cr, ci; |
| 77 |
int i; |
| 78 |
int ok = 1; |
| 79 |
xr[0] = 0x1.0b1600p-133; |
| 80 |
xi[0] = 0x1.5e1c28p+54; |
| 81 |
yr[0] = -0x1.cdec8cp-119; |
| 82 |
yi[0] = 0x1.1e72ccp+32; |
| 83 |
zr[0] = 0x1.38e502p+22; |
| 84 |
zi[0] = -0x1.f89220p-129; |
| 85 |
|
| 86 |
xr[1] = -0x1.b1bee2p+121; |
| 87 |
xi[1] = -0x1.cb403ep-59; |
| 88 |
yr[1] = 0x1.480000p-144; |
| 89 |
yi[1] = -0x1.c66fc4p+5; |
| 90 |
zr[1] = -0x1.60b8cap-34; |
| 91 |
zi[1] = -0x1.e8b02ap+115; |
| 92 |
|
| 93 |
xr[2] = -0x1.3f6e00p-97; |
| 94 |
xi[2] = -0x1.c00000p-146; |
| 95 |
yr[2] = 0x1.000000p-148; |
| 96 |
yi[2] = -0x1.0c4e70p-91; |
| 97 |
zr[2] = 0x1.aa50d0p-55; |
| 98 |
zi[2] = -0x1.30c746p-6; |
| 99 |
|
| 100 |
xr[3] = 0x1.000000p-148; |
| 101 |
xi[3] = 0x1.f4bc04p-84; |
| 102 |
yr[3] = 0x1.00ad74p-20; |
| 103 |
yi[3] = 0x1.2ad02ep-85; |
| 104 |
zr[3] = 0x1.1102ccp-127; |
| 105 |
zi[3] = 0x1.f369a4p-64; |
| 106 |
|
| 107 |
for (i = 0; i < 4; i++) |
| 108 |
{ |
| 109 |
__real__ a = xr[i]; |
| 110 |
__imag__ a = xi[i]; |
| 111 |
__real__ b = yr[i]; |
| 112 |
__imag__ b = yi[i]; |
| 113 |
__real__ z = zr[i]; |
| 114 |
__imag__ z = zi[i]; |
| 115 |
c = a / b; |
| 116 |
cr = __real__ c; |
| 117 |
ci = __imag__ c; |
| 118 |
|
| 119 |
if (!match (c,z)){ |
| 120 |
ok = 0; |
| 121 |
} |
| 122 |
} |
| 123 |
if (!ok) |
| 124 |
abort (); |
| 125 |
exit (0); |
| 126 |
} |