From 71571a1432b2f5acb85d3d220a97a55efb7dc64d Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 15 Mar 2023 16:06:58 +0100 Subject: [PATCH] Add function atanh to .control section --- src/frontend/parse.c | 1 + src/include/ngspice/fteext.h | 1 + src/maths/cmaths/cmath1.c | 32 ++++++++++++++++++++++++++++++++ src/maths/cmaths/cmath1.h | 1 + 4 files changed, 35 insertions(+) diff --git a/src/frontend/parse.c b/src/frontend/parse.c index 89581b964..16666a1bc 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -343,6 +343,7 @@ struct func ft_funcs[] = { { "cosh", cx_cosh }, { "tanh", cx_tanh }, { "atan", cx_atan }, + { "atanh", cx_atanh }, { "sortorder", cx_sortorder }, { "norm", cx_norm }, { "rnd", cx_rnd }, diff --git a/src/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index 5907badb4..7c8a383b7 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -74,6 +74,7 @@ extern void *cx_cosh(void *, short int , int , int *, short int *); extern void *cx_tan(void *, short int , int , int *, short int *); extern void *cx_tanh(void *, short int , int , int *, short int *); extern void *cx_atan(void *, short int , int , int *, short int *); +extern void *cx_atanh(void*, short int, int, int*, short int*); extern void *cx_floor(void *, short int , int , int *, short int *); extern void *cx_ceil(void *, short int , int , int *, short int *); extern void *cx_nint(void *, short int , int , int *, short int *); diff --git a/src/maths/cmaths/cmath1.c b/src/maths/cmaths/cmath1.c index 3f36ecd33..d90128882 100644 --- a/src/maths/cmaths/cmath1.c +++ b/src/maths/cmaths/cmath1.c @@ -21,6 +21,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group #include +#include #include "ngspice/ngspice.h" #include "ngspice/memory.h" @@ -862,6 +863,37 @@ cx_tanh(void *data, short int type, int length, int *newlength, short int *newty } } +/** atanh of a complex vector: use C99 function catanh. */ +void* +cx_atanh(void* data, short int type, int length, int* newlength, short int* newtype) +{ + if (type == VF_COMPLEX) { + ngcomplex_t* d = alloc_c(length); + *newtype = VF_COMPLEX; + *newlength = length; + ngcomplex_t* cc = (ngcomplex_t*)data; + int i; + for (i = 0; i < length; i++) { + _Dcomplex midin = _Cbuild(cc->cx_real, cc->cx_imag); + _Dcomplex midout = catanh(midin); + d[i].cx_real = creal(midout); + d[i].cx_imag = cimag(midout); + } + return ((void*)d); + } + else { + double* d = alloc_d(length); + *newtype = VF_REAL; + *newlength = length; + double* cc = (double*)data; + int i; + for (i = 0; i < length; i++) { + d[i] = atanh(cc[i]); + } + return ((void*)d); + } +} + /** atan of a complex vector: return atan of the real part. */ void * cx_atan(void *data, short int type, int length, int *newlength, short int *newtype) diff --git a/src/maths/cmaths/cmath1.h b/src/maths/cmaths/cmath1.h index 24671f60a..fbda4bd54 100644 --- a/src/maths/cmaths/cmath1.h +++ b/src/maths/cmaths/cmath1.h @@ -32,6 +32,7 @@ void * cx_cosh(void *data, short int type, int length, int *newlength, short int void * cx_tan(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_tanh(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_atan(void *data, short int type, int length, int *newlength, short int *newtype); +void * cx_atanh(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_sortorder(void *data, short int type, int length, int *newlength, short int *newtype);