int main (void) { double complex z = ctanh (1); // behaves like real tanh along the real line printf ("tanh(1+0i) = %f%+fi (tanh(1)=%f)\n", creal (z), cimag (z), tanh (1)); double complex z2 = ctanh (I); // behaves like tangent along the imaginary line printf ("tanh(0+1i) = %f%+fi ( tan(1)=%f)\n", creal (z2), cimag (z2), tan (1)); return 0; }
//## Complex Complex.ctanhl(); static KMETHOD Complex_ctanhl(KonohaContext *kctx, KonohaStack *sfp) { kComplex *kc = (kComplex *) sfp[0].asObject; long double _Complex zl = (long double _Complex)kc->z; long double ret = ctanh(zl); KReturnFloatValue(ret); }
//## Complex Complex.ctanhf(); static KMETHOD Complex_ctanhf(KonohaContext *kctx, KonohaStack *sfp) { kComplex *kc = (kComplex *) sfp[0].asObject; float _Complex zf = (float _Complex)kc->z; float ret = ctanh(zf); KReturnFloatValue(ret); }
double complex ctan(double complex z) { /* ctan(z) = -I * ctanh(I * z) */ z = ctanh(cpack(-cimag(z), creal(z))); return (cpack(cimag(z), -creal(z))); }
dcomplex ctan(dcomplex z) { double x, y; dcomplex ans, ct; x = D_RE(z); y = D_IM(z); D_RE(z) = y; D_IM(z) = -x; ct = ctanh(z); D_RE(ans) = -D_IM(ct); D_IM(ans) = D_RE(ct); return (ans); }
void cmplx (double _Complex z) { cabs (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 129 } */ cacos (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 131 } */ cacosh (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 133 } */ carg (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 135 } */ casin (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 137 } */ casinh (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 139 } */ catan (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 141 } */ catanh (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 143 } */ ccos (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 145 } */ ccosh (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 147 } */ cexp (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 149 } */ cimag (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 151 } */ clog (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 153 } */ conj (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 155 } */ cpow (z, z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 157 } */ cproj (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 159 } */ creal (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 161 } */ csin (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 163 } */ csinh (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 165 } */ csqrt (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 167 } */ ctan (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 169 } */ ctanh (z); /* { dg-warning "incompatible implicit" } */ /* { dg-message "include ..complex.h.." "" { target *-*-* } 171 } */ }
int main(int argc, char **argv) { if(argc < 3) { print_usage(); exit(EXIT_FAILURE); } //json2list(argv[1]); json_object *jobj = json_tokener_parse(argv[2]); if(json_object_get_type(jobj)!=json_type_array) { printf("Input error: second argument is not a JSON array.\n"); printf("%s\n", argv[2]); printf("%s\n", argv[3]); exit(EXIT_FAILURE); } struct layer *layerlist = layers2list(argv[1]); int nf = json_object_array_length(jobj); int i; json_object *jvalue; float omega; float complex g, iwm, coth_gd; struct layer *l; float complex Z; printf("freq Zreal Zimag rhoa\n"); for(i = 0; i < nf; ++i) { jvalue = json_object_array_get_idx(jobj, i); omega = json_object_get_double(jvalue); l = layerlist; Z = csqrt(I * omega * mu / l->sigma); l = l->prev; while(l) { g = csqrt(I * omega * mu * l->sigma); iwm = I * omega * mu; coth_gd = 1 / ctanh(g * l->d); Z *= g / iwm; Z = (Z * coth_gd + 1) / (Z + coth_gd); Z *= iwm / g; l = l->prev; } printf("%f %f %f %f\n", omega, creal(Z), cimag(Z), pow(cabs(Z), 2) / (omega * mu)); } cleanup(layerlist); return 0; }
double complex Heston::logCF(const double &S, const double complex &u) const { double complex temp1,temp2,temp3, v1, v2,v3, gamma, result; v1 = kappa-I*rho*sigma*u; v2 = u*u+I*u; v3 = kappa*theta/(sigma*sigma); gamma = sigma*sigma*v2+v1*v1; gamma = cpow(gamma,.5); temp1 = cexp(I*u*(log(S)+(r-q)*T)+v3*T*v1); temp2 = ccosh(gamma*T/2.0)+v1/gamma*csinh(gamma*T/2.0); result = temp1/cpow(temp2,2.0*v3); temp1 = v0*v2; //v0 is class variable defined in .h file temp2 = gamma/ctanh(gamma*T/2.0)+v1; temp3 = cexp(-temp1/temp2); result = result*temp3; return result; }
int main() { double x,y; double complex result; #ifdef XXXXX for (x = -10; x < 10; x += 0.5) for (y=-10; y < 10; y += 0.5) { result = ccosh(x + I *y); printf("%f %f %f %f %f %f\n",x,y,(double)cosh(x)*cos(y),(double)creal(result),(double)sinh(x)*sin(y),(double)cimag(result)); } for (x = -10; x < 10; x += 0.5) for (y=-10; y < 10; y += 0.5) { result = csinh(x + I *y); printf("%f %f %f %f %f %f\n",x,y,(double)sinh(x)*cos(y),(double)creal(result),(double)cosh(x)*sin(y),(double)cimag(result)); } #endif for (x = -10; x < 10; x += 0.5) for (y=-10; y < 10; y += 0.5) { double d = coshl( 2.0L * x ) + cosl( 2.0L * y ); result = ctanh(x + I *y); printf("%f %f %f %f %f %f\n",x,y,(double)sinh(2.0*x)/d,(double)creal(result),(double)sin(2.0*y)/d,(double)cimag(result)); } }
void docomplex (void) { #ifndef NO_DOUBLE complex double ca, cb, cc; double f1; ca = 1.0 + 1.0 * I; cb = 1.0 - 1.0 * I; f1 = cabs (ca); fprintf (stdout, "cabs : %f\n", f1); cc = cacos (ca); fprintf (stdout, "cacos : %f %fi\n", creal (cc), cimag (cc)); cc = cacosh (ca); fprintf (stdout, "cacosh : %f %fi\n", creal (cc), cimag (cc)); f1 = carg (ca); fprintf (stdout, "carg : %f\n", f1); cc = casin (ca); fprintf (stdout, "casin : %f %fi\n", creal (cc), cimag (cc)); cc = casinh (ca); fprintf (stdout, "casinh : %f %fi\n", creal (cc), cimag (cc)); cc = catan (ca); fprintf (stdout, "catan : %f %fi\n", creal (cc), cimag (cc)); cc = catanh (ca); fprintf (stdout, "catanh : %f %fi\n", creal (cc), cimag (cc)); cc = ccos (ca); fprintf (stdout, "ccos : %f %fi\n", creal (cc), cimag (cc)); cc = ccosh (ca); fprintf (stdout, "ccosh : %f %fi\n", creal (cc), cimag (cc)); cc = cexp (ca); fprintf (stdout, "cexp : %f %fi\n", creal (cc), cimag (cc)); f1 = cimag (ca); fprintf (stdout, "cimag : %f\n", f1); cc = clog (ca); fprintf (stdout, "clog : %f %fi\n", creal (cc), cimag (cc)); cc = conj (ca); fprintf (stdout, "conj : %f %fi\n", creal (cc), cimag (cc)); cc = cpow (ca, cb); fprintf (stdout, "cpow : %f %fi\n", creal (cc), cimag (cc)); cc = cproj (ca); fprintf (stdout, "cproj : %f %fi\n", creal (cc), cimag (cc)); f1 = creal (ca); fprintf (stdout, "creal : %f\n", f1); cc = csin (ca); fprintf (stdout, "csin : %f %fi\n", creal (cc), cimag (cc)); cc = csinh (ca); fprintf (stdout, "csinh : %f %fi\n", creal (cc), cimag (cc)); cc = csqrt (ca); fprintf (stdout, "csqrt : %f %fi\n", creal (cc), cimag (cc)); cc = ctan (ca); fprintf (stdout, "ctan : %f %fi\n", creal (cc), cimag (cc)); cc = ctanh (ca); fprintf (stdout, "ctanh : %f %fi\n", creal (cc), cimag (cc)); #endif }
f = casinhf(f); ld = casinhl(ld); TEST_TRACE(C99 7.3.6.3) d = catanh(d); f = catanhf(f); ld = catanhl(ld); TEST_TRACE(C99 7.3.6.4) d = ccosh(d); f = ccoshf(f); ld = ccoshl(ld); TEST_TRACE(C99 7.3.6.5) d = csinh(d); f = csinhf(f); ld = csinhl(ld); TEST_TRACE(C99 7.3.6.6) d = ctanh(d); f = ctanhf(f); ld = ctanhl(ld); TEST_TRACE(C99 7.3.7.1) d = cexp(d); f = cexpf(f); ld = cexpl(ld); TEST_TRACE(C99 7.3.7.2) d = clog(d); f = clogf(f); ld = clogl(ld); TEST_TRACE(C99 7.3.8.1) d = cabs(d); f = cabsf(f); ld = cabsl(ld); TEST_TRACE(C99 7.3.8.2)
CAMLprim value math_ctanh(value x) { CAMLparam1(x); CAMLreturn(caml_copy_complex(ctanh(Complex_val(x)))); }
void test06 ( ) /******************************************************************************/ /* Purpose: TEST06: intrinsic functions for double complex variables. Licensing: This code is distributed under the GNU LGPL license. Modified: 07 November 2010 Author: John Burkardt */ { double complex a = {1.0 + 2.0 * I}; printf ( "\n" ); printf ( "TEST06\n" ); printf ( " Apply intrinsic functions to DOUBLE COMPLEX variables\n" ); /* Print them. */ printf ( "\n" ); /* Note that "I" by itself is NOT a complex number, nor is it the imaginary unit. You have to cast it to ( complex ) or ( double complex ) or multiply it by a float or double before it results in a numerical result. */ printf ( " ( double complex ) I = (%14.6g,%14.6g)\n", ( double complex ) I ); printf ( " a = (%14.6g,%14.6g)\n", a ); printf ( " - a = (%14.6g,%14.6g)\n", - a ); printf ( " a + 3 = (%14.6g,%14.6g)\n", a + 3 ); printf ( " a + (0,5) = (%14.6g,%14.6g)\n", a + ( 0, 5 ) ); printf ( " 4 * a = (%14.6g,%14.6g)\n", 4 * a ); printf ( " a / 8 = (%14.6g,%14.6g)\n", a / 8 ); printf ( " a * a = (%14.6g,%14.6g)\n", a * a ); printf ( " cpow ( a, 2 ) = (%14.6g,%14.6g)\n", cpow ( a, 2 ) ); printf ( " cpow ( 2, a ) = (%14.6g,%14.6g)\n", cpow ( 2, a ) ); printf ( " cpow ( a, a ) = (%14.6g,%14.6g)\n", cpow ( a, a ) ); printf ( " 1/a = (%14.6g,%14.6g)\n", 1.0 / a ); printf ( "\n" ); printf ( " cabs(a) = %14.6g\n", cabs ( a ) ); printf ( " cacos(a) = (%14.6g,%14.6g)\n", cacos ( a ) ); printf ( " cacosh(a) = (%14.6g,%14.6g)\n", cacosh ( a ) ); printf ( " carg(a) = %14.6g\n", carg ( a ) ); printf ( " casin(a) = (%14.6g,%14.6g)\n", casin ( a ) ); printf ( " casinh(a) = (%14.6g,%14.6g)\n", casinh ( a ) ); printf ( " catan(a) = (%14.6g,%14.6g)\n", creal ( catan ( a ) ), cimag ( catan ( a ) ) ); printf ( " catanh(a) = (%14.6g,%14.6g)\n", creal ( catanh ( a ) ), cimag ( catanh ( a ) ) ); printf ( " ccos(a) = (%14.6g,%14.6g)\n", creal ( ccos ( a ) ), cimag ( ccos ( a ) ) ); printf ( " ccosh(a) = (%14.6g,%14.6g)\n", creal ( ccosh ( a ) ), cimag ( ccosh ( a ) ) ); printf ( " cexp(a) = (%14.6g,%14.6g)\n", creal ( cexp ( a ) ), cimag ( cexp ( a ) ) ); printf ( " cimag(a) = %14.6g\n", cimag ( a ) ); printf ( " clog(a) = (%14.6g,%14.6g)\n", creal ( clog ( a ) ), cimag ( clog ( a ) ) ); printf ( " (double complex)(1) = (%14.6g,%14.6g)\n", creal ( ( double complex ) ( 1 ) ), cimag ( ( double complex ) ( 1 ) ) ); printf ( " (double complex)(4.0) = (%14.6g,%14.6g)\n", creal ( ( double complex ) ( 4.0 ) ), cimag ( ( double complex ) ( 4.0 ) ) ); printf ( " conj(a) = (%14.6g,%14.6g)\n", creal ( conj ( a ) ), cimag ( conj ( a ) ) ); printf ( " cproj(a) = (%14.6g,%14.6g)\n", creal ( cproj ( a ) ), cimag ( cproj ( a ) ) ); printf ( " creal(a) = %14.6g\n", creal ( a ) ); printf ( " csin(a) = (%14.6g,%14.6g)\n", creal ( csin ( a ) ), cimag ( csin ( a ) ) ); printf ( " csinh(a) = (%14.6g,%14.6g)\n", creal ( csinh ( a ) ), cimag ( csinh ( a ) ) ); printf ( " csqrt(a) = (%14.6g,%14.6g)\n", creal ( csqrt ( a ) ), cimag ( csqrt ( a ) ) ); printf ( " ctan(a) = (%14.6g,%14.6g)\n", creal ( ctan ( a ) ), cimag ( ctan ( a ) ) ); printf ( " ctanh(a) = (%14.6g,%14.6g)\n", creal ( ctanh ( a ) ), cimag ( ctanh ( a ) ) ); printf ( " (int)(a) = %10d\n", ( int ) ( a ) ); return; }
TEST(complex, ctanh) { ASSERT_EQ(0.0, ctanh(0)); }