void escribeMatrizArchivo_completo(matriz * mtz, matriz * epsilon1, matriz * epsilon2, long double *angulos, long double delta1, long double delta2, char* conjugado_corto, char *conjugado_largo, char *nombre, int fila_noAstig, int columna_noAstig, long double astigmatismo) { FILE *archivo; archivo = fopen(nombre,"w"); int fila, columna; fprintf(archivo, "Configuracion optima,\n\n"); fprintf(archivo,"delta 1 [m],Theta 1 [rad],delta 2 [m],Theta 2 [rad],Conjugado corto, Conjugado largo, Astigmatismo (spot tan / spot sag)\n"); fprintf(archivo,"%.15Le,%.15Le,%.15Le,%.15Le,%s,%s,%.15Le\n\n",delta1+creall(obtieneElemento(epsilon1,1,fila_noAstig)),angulos[0],delta2+creall(obtieneElemento(epsilon2,1,columna_noAstig)),angulos[1],conjugado_corto,conjugado_largo, creall(astigmatismo)); fprintf(archivo, "epsilon 1 [m],epsilon2 [m]\n"); fprintf(archivo, "%.15Le,%.15Le,\n\n",creall(obtieneElemento(epsilon1,1,fila_noAstig)),creall(obtieneElemento(epsilon2,1,columna_noAstig))); fprintf(archivo, " ,epsilon 2 [m],"); for(columna=1;columna<=mtz->columnas;columna++) fprintf(archivo, "%.15Le,",creall(elem(epsilon2,1,columna))); fprintf(archivo, "\nepsilon 1 [m],\n"); for (fila=1;fila<=mtz->filas;fila++) { fprintf(archivo,"%.15Le, ,",creall(elem(epsilon1,1,fila))); for(columna=1;columna<=mtz->columnas;columna++) { //Imprime el elemento de punto flotante fprintf(archivo, "%.15Le+%.15Lei,", creall(elem(mtz,fila,columna)),cimagl(elem(mtz,fila,columna))); //fprintf(archivo, "%6.5f\t", cimagl(elem(mtz,fila,columna))); } fprintf(archivo,"\n"); } fclose(archivo); }
void escribeMatrizDoubleArchivo(matriz * mtz, char *nombre) { FILE *archivo; archivo = fopen(nombre,"w"); int fila, columna; fprintf(archivo,"double datos={"); for (fila=1;fila<=mtz->filas-1;fila++) { fprintf(archivo,"{"); for(columna=1;columna<=mtz->columnas;columna++) { //Imprime el elemento de punto flotante fprintf(archivo, "%.15Le,", creall(elem(mtz,fila,columna))); //fprintf(archivo, "%6.5f\t", cimagl(elem(mtz,fila,columna))); } fprintf(archivo,"},\n"); } fila=mtz->filas; fprintf(archivo,"{"); for(columna=1;columna<=mtz->columnas;columna++) { //Imprime el elemento de punto flotante fprintf(archivo, "%.15Le,", creall(elem(mtz,fila,columna))); //fprintf(archivo, "%6.5f\t", cimagl(elem(mtz,fila,columna))); } fprintf(archivo,"}};"); fclose(archivo); }
/* * Test the handling of NaNs. */ static void test_nans() { assert(creall(t_csqrt(CMPLXL(INFINITY, NAN))) == INFINITY); assert(isnan(cimagl(t_csqrt(CMPLXL(INFINITY, NAN))))); assert(isnan(creall(t_csqrt(CMPLXL(-INFINITY, NAN))))); assert(isinf(cimagl(t_csqrt(CMPLXL(-INFINITY, NAN))))); assert_equal(t_csqrt(CMPLXL(NAN, INFINITY)), CMPLXL(INFINITY, INFINITY)); assert_equal(t_csqrt(CMPLXL(NAN, -INFINITY)), CMPLXL(INFINITY, -INFINITY)); assert_equal(t_csqrt(CMPLXL(0.0, NAN)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(-0.0, NAN)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(42.0, NAN)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(-42.0, NAN)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(NAN, 0.0)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(NAN, -0.0)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(NAN, 42.0)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(NAN, -42.0)), CMPLXL(NAN, NAN)); assert_equal(t_csqrt(CMPLXL(NAN, NAN)), CMPLXL(NAN, NAN)); }
long double complex catanl(long double complex z) { long double complex w; w = catanhl(CMPLXL(cimagl(z), creall(z))); return (CMPLXL(cimagl(w), creall(w))); }
long double complex cacosl(long double complex z) { long double x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x; int sx, sy; int B_is_usable; long double complex w; x = creall(z); y = cimagl(z); sx = signbit(x); sy = signbit(y); ax = fabsl(x); ay = fabsl(y); if (isnan(x) || isnan(y)) { if (isinf(x)) return (CMPLXL(y + y, -INFINITY)); if (isinf(y)) return (CMPLXL(x + x, -y)); if (x == 0) return (CMPLXL(pio2_hi + pio2_lo, y + y)); return (CMPLXL(nan_mix(x, y), nan_mix(x, y))); } if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { w = clog_for_large_values(z); rx = fabsl(cimagl(w)); ry = creall(w) + m_ln2; if (sy == 0) ry = -ry; return (CMPLXL(rx, ry)); } if (x == 1 && y == 0) return (CMPLXL(0, -y)); raise_inexact(); if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) return (CMPLXL(pio2_hi - (x - pio2_lo), -y)); do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x); if (B_is_usable) { if (sx == 0) rx = acosl(B); else rx = acosl(-B); } else { if (sx == 0) rx = atan2l(sqrt_A2mx2, new_x); else rx = atan2l(sqrt_A2mx2, -new_x); } if (sy == 0) ry = -ry; return (CMPLXL(rx, ry)); }
long double complex ccosl(long double complex z) { long double complex w; long double ch, sh; _cchshl(cimagl(z), &ch, &sh); w = cosl(creall(z)) * ch - (sinl(creall(z)) * sh) * I; return w; }
long double complex csinl(long double complex z) { long double complex w; long double ch, sh; cchshl(cimagl(z), &ch, &sh); w = sinl(creall(z)) * ch + (cosl(creall(z)) * sh) * I; return (w); }
// FIXME long double complex casinl(long double complex z) { long double complex w; long double x, y; x = creall(z); y = cimagl(z); w = CMPLXL(1.0 - (x - y)*(x + y), -2.0*x*y); long double complex r = clogl(CMPLXL(-y, x) + csqrtl(w)); return CMPLXL(cimagl(r), -creall(r)); }
void imprimeListaReal(matriz * ejeX, matriz * ejeY, matriz * datosTan, matriz * datosSag, char* rutaArchivo) { FILE *archivo; archivo = fopen(rutaArchivo,"w"); fprintf(archivo,"#Datos a graficar con Gnuplot, e1, e2, tan, sag\n"); for(int i=1;i<=ejeX->columnas;i++) { for(int j=1;j<=ejeY->columnas;j++) { fprintf(archivo,"%Le %Le %Le %Le\n",creall(obtieneElemento(ejeX,1,i)),creall(obtieneElemento(ejeY,1,j)),creall(obtieneElemento(datosTan,i,j)),creall(obtieneElemento(datosSag,i,j))); } } fclose(archivo); }
static long double complex clog_for_large_values(long double complex z) { long double x, y; long double ax, ay, t; x = creall(z); y = cimagl(z); ax = fabsl(x); ay = fabsl(y); if (ax < ay) { t = ax; ax = ay; ay = t; } if (ax > HALF_MAX) return (CMPLXL(logl(hypotl(x / m_e, y / m_e)) + 1, atan2l(y, x))); if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN) return (CMPLXL(logl(hypotl(x, y)), atan2l(y, x))); return (CMPLXL(logl(ax * ax + ay * ay) / 2, atan2l(y, x))); }
long double complex catanl(long double complex z) { long double complex w; long double a, t, x, x2, y; x = creall(z); y = cimagl(z); if ((x == 0.0L) && (y > 1.0L)) goto ovrf; x2 = x * x; a = 1.0L - x2 - (y * y); if (a == 0.0L) goto ovrf; t = atan2l(2.0L * x, a) * 0.5L; w = redupil(t); t = y - 1.0L; a = x2 + (t * t); if (a == 0.0L) goto ovrf; t = y + 1.0L; a = (x2 + (t * t)) / a; w = w + (0.25L * logl(a)) * I; return (w); ovrf: /*mtherr( "catanl", OVERFLOW );*/ w = LDBL_MAX + LDBL_MAX * I; return (w); }
long double complex casinhl(long double complex z) { long double x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y; int B_is_usable; long double complex w; x = creall(z); y = cimagl(z); ax = fabsl(x); ay = fabsl(y); if (isnan(x) || isnan(y)) { if (isinf(x)) return (CMPLXL(x, y + y)); if (isinf(y)) return (CMPLXL(y, x + x)); if (y == 0) return (CMPLXL(x + x, y)); return (CMPLXL(nan_mix(x, y), nan_mix(x, y))); } if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { if (signbit(x) == 0) w = clog_for_large_values(z) + m_ln2; else w = clog_for_large_values(-z) + m_ln2; return (CMPLXL(copysignl(creall(w), x), copysignl(cimagl(w), y))); } if (x == 0 && y == 0) return (z); raise_inexact(); if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) return (z); do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y); if (B_is_usable) ry = asinl(B); else ry = atan2l(new_y, sqrt_A2my2); return (CMPLXL(copysignl(rx, x), copysignl(ry, y))); }
long double complex cprojl(long double complex z) { if (!isinf(creall(z)) && !isinf(cimagl(z))) return (z); else return (cpackl(INFINITY, copysignl(0.0, cimagl(z)))); }
long double complex cacosl(long double complex z) { long double complex w; w = casinl(z); w = (PIO2L - creall(w)) - cimagl(w) * I; return (w); }
long double complex cexpl(long double complex z) { long double complex w; long double r; r = expl(creall(z)); w = r * cosl(cimagl(z)) + (r * sinl(cimagl(z))) * I; return (w); }
// FIXME long double complex casinl(long double complex z) { long double complex w; long double x, y; x = creall(z); y = cimagl(z); w = cpackl(1.0 - (x - y)*(x + y), -2.0*x*y); return clogl(cpackl(-y, x) + csqrtl(w)); }
long double complex ctanl(long double complex z) { long double complex w; long double d; d = cosl(2.0L * creall(z)) + coshl(2.0L * cimagl(z)); if (fabsl(d) < 0.25L) d = _ctansl(z); if (d == 0.0L) { /* mtherr ("ctan", OVERFLOW); */ w = MAXNUM + MAXNUM * I; return w; } w = sinl(2.0L * creall(z)) / d + (sinhl(2.0L * cimagl(z)) / d) * I; return w; }
long double complex csinhl(long double complex z) { long double complex w; long double x, y; x = creall(z); y = cimagl(z); w = sinhl(x) * cosl(y) + (coshl(x) * sinl(y)) * I; return w; }
/* * Test whether csqrt(a + bi) works for inputs that are large enough to * cause overflow in hypot(a, b) + a. In this case we are using * csqrt(115 + 252*I) == 14 + 9*I * scaled up to near MAX_EXP. */ static void test_overflow(int maxexp) { long double a, b; long double complex result; a = ldexpl(115 * 0x1p-8, maxexp); b = ldexpl(252 * 0x1p-8, maxexp); result = t_csqrt(CMPLXL(a, b)); assert(creall(result) == ldexpl(14 * 0x1p-4, maxexp / 2)); assert(cimagl(result) == ldexpl(9 * 0x1p-4, maxexp / 2)); }
long double complex clogl(long double complex z) { long double complex w; long double p, rr; rr = cabsl(z); p = logl(rr); rr = atan2l(cimagl(z), creall(z)); w = p + rr * I; return w; }
long double complex ctanhl(long double complex z) { long double complex w; long double x, y, d; x = creall(z); y = cimagl(z); d = coshl(2.0L * x) + cosl(2.0L * y); w = sinhl(2.0L * x) / d + (sinl(2.0L * y) / d) * I; return (w); }
void escribeMatrizArchivo_ejes(matriz * mtz, matriz * epsilon1, matriz * epsilon2, char *nombre) { FILE *archivo; archivo = fopen(nombre,"w"); int fila, columna; fprintf(archivo, " ,epsilon 2 [m],"); for(columna=1;columna<=mtz->columnas;columna++) fprintf(archivo, "%.15Le,",creall(elem(epsilon2,1,columna))); fprintf(archivo, "\nepsilon 1 [m],\n"); for (fila=1;fila<=mtz->filas;fila++) { fprintf(archivo,"%.15Le, ,",creall(elem(epsilon1,1,fila))); for(columna=1;columna<=mtz->columnas;columna++) { //Imprime el elemento de punto flotante fprintf(archivo, "%.15Le+%.15Lei,", creall(elem(mtz,fila,columna)),cimagl(elem(mtz,fila,columna))); //fprintf(archivo, "%6.5f\t", cimagl(elem(mtz,fila,columna))); } fprintf(archivo,"\n"); } fclose(archivo); }
long double complex clogl(long double complex z) { long double complex w; long double p, rr; /*rr = sqrt(z->r * z->r + z->i * z->i);*/ p = cabsl(z); p = logl(p); rr = atan2l(cimagl(z), creall(z)); w = p + rr * I; return (w); }
int classify(long double _Complex x) { if (x == 0) return zero; if (isinf(creall(x)) || isinf(cimagl(x))) return inf; if (isnan(creall(x)) && isnan(cimagl(x))) return NaN; if (isnan(creall(x))) { if (cimagl(x) == 0) return NaN; return non_zero_nan; } if (isnan(cimagl(x))) { if (creall(x) == 0) return NaN; return non_zero_nan; } return non_zero; }
long double complex catanhl(long double complex z) { long double x, y, ax, ay, rx, ry; x = creall(z); y = cimagl(z); ax = fabsl(x); ay = fabsl(y); if (y == 0 && ax <= 1) return (CMPLXL(atanhl(x), y)); if (x == 0) return (CMPLXL(x, atanl(y))); if (isnan(x) || isnan(y)) { if (isinf(x)) return (CMPLXL(copysignl(0, x), y + y)); if (isinf(y)) return (CMPLXL(copysignl(0, x), copysignl(pio2_hi + pio2_lo, y))); return (CMPLXL(nan_mix(x, y), nan_mix(x, y))); } if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) return (CMPLXL(real_part_reciprocal(x, y), copysignl(pio2_hi + pio2_lo, y))); if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) { raise_inexact(); return (z); } if (ax == 1 && ay < LDBL_EPSILON) rx = (m_ln2 - logl(ay)) / 2; else rx = log1pl(4 * ax / sum_squares(ax - 1, ay)) / 4; if (ax == 1) ry = atan2l(2, -ay) / 2; else if (ay < LDBL_EPSILON) ry = atan2l(2 * ay, (1 - ax) * (1 + ax)) / 2; else ry = atan2l(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2; return (CMPLXL(copysignl(rx, x), copysignl(ry, y))); }
int imprimeMatriz(matriz * mtz) { if (!mtz) return -1; int fila, columna; for (fila=1;fila<=mtz->filas;++fila) { for(columna=1;columna<=mtz->columnas;++columna) { //Imprime el elemento de punto flotante printf("%.15Le+%.15Lei ", creall(elem(mtz,fila,columna)),cimagl(elem(mtz,fila,columna))); } printf("\n"); } return 0; }
long double complex cacoshl(long double complex z) { long double complex w; long double rx, ry; w = cacosl(z); rx = creall(w); ry = cimagl(w); if (isnan(rx) && isnan(ry)) return (CMPLXL(ry, rx)); if (isnan(rx)) return (CMPLXL(fabsl(ry), rx)); if (isnan(ry)) return (CMPLXL(ry, ry)); return (CMPLXL(fabsl(ry), copysignl(rx, cimagl(z)))); }
long double _ctansl(long double complex z) { long double f, x, x2, y, y2, rn, t; long double d; x = fabsl(2.0L * creall(z)); y = fabsl(2.0L * cimagl(z)); x = _redupil(x); x = x * x; y = y * y; x2 = 1.0; y2 = 1.0; f = 1.0; rn = 0.0; d = 0.0; do { rn += 1.0L; f *= rn; rn += 1.0L; f *= rn; x2 *= x; y2 *= y; t = y2 + x2; t /= f; d += t; rn += 1.0L; f *= rn; rn += 1.0L; f *= rn; x2 *= x; y2 *= y; t = y2 - x2; t /= f; d += t; } while (fabsl(t/d) > MACHEPL); return d; }
long double complex cpowl(long double complex a, long double complex z) { long double complex w; long double x, y, r, theta, absa, arga; x = creall(z); y = cimagl(z); absa = cabsl(a); if (absa == 0.0L) { return (0.0L + 0.0L * I); } arga = cargl(a); r = powl(absa, x); theta = x * arga; if (y != 0.0L) { r = r * expl(-y * arga); theta = theta + y * logl(absa); } w = r * cosl(theta) + (r * sinl(theta)) * I; return (w); }
long double complex catanl(long double complex z) { long double complex w; long double a, t, x, x2, y; x = creall(z); y = cimagl(z); if ((x == 0.0L) && (y > 1.0L)) goto ovrf; x2 = x * x; a = 1.0L - x2 - (y * y); if (a == 0.0) goto ovrf; t = 0.5L * atan2l(2.0L * x, a); w = _redupil(t); t = y - 1.0L; a = x2 + (t * t); if (a == 0.0L) goto ovrf; t = y + 1.0L; a = (x2 + (t * t))/a; w = w + (0.25L * logl(a)) * I; return w; ovrf: #if 0 mtherr ("catanl", OVERFLOW); #endif w = HUGE_VALL + HUGE_VALL * I; return w; }