The GSL-FFI-COMPLEX module

The GNU Scientific Library (GSL) handles complex numbers (gsl_complex) as direct structures rather than pointers, meaning functions like gsl_complex_rect and gsl_complex_polar return values by copy. Since the Dylan C-FFI does not natively support functions that return or accept structs by value (a common limitation in many cross-language FFI systems) this module introduces a “shim” layer.

We provide a set of C wrapper functions in complex-shim.c that adapt the GSL interface by handling gsl_complex structures via pointers, ensuring compatibility with Dylan’s FFI.

Complex numbers

gsl-complex Function
Signature:

gsl-complex (real imag) => (complex)

Parameters:
  • real – A <c-double>. The real part of the complex number.

  • imag – A <c-double>. The imaginary part of the complex number.

Values:
  • complex – A <gsl-complex*>.

Discussion:

Creates a new complex number with the given real and imaginary parts.

gsl-complex-real Function
Signature:

gsl-complex-real (complex) => (real)

Parameters:
  • complex – A <gsl-complex*>. The complex number.

Values:
  • real – A <c-double>. The real part of the complex number.

Discussion:

Returns the real part of a complex number.

gsl-complex-imag Function
Signature:

gsl-complex-imag (complex) => (imag)

Parameters:
  • complex – A <gsl-complex*>. The complex number.

Values:
  • imag – A <c-double>. The imaginary part of the complex number.

Discussion:

Returns the imaginary part of a complex number.

Properties of complex numbers

gsl-complex-abs Function
Signature:

gsl-complex-abs (complex) => (abs)

Parameters:
  • complex – A <gsl-complex*>. The complex number.

Values:
  • abs – A <c-double>. The absolute value of the complex number.

Discussion:

Returns the absolute value of a complex number.

gsl-complex-abs2 Function
Signature:

gsl-complex-abs2 (complex) => (abs2)

Parameters:
  • complex – A <gsl-complex*>. The complex number.

Values:
  • abs2 – A <c-double>. The squared absolute value of the complex number.

Discussion:

Returns the squared absolute value of a complex number.

gsl-complex-arg Function
Signature:

gsl-complex-arg (complex) => (arg)

Parameters:
  • complex – A <gsl-complex*>. The complex number.

Values:
  • arg – A <c-double>. The argument of the complex number.

Discussion:

Returns the argument of a complex number.

gsl-complex-logabs Function
Signature:

gsl-complex-logabs (complex) => (logabs)

Parameters:
  • complex – A <gsl-complex*>. The complex number.

Values:
  • logabs – A <c-double>. The natural logarithm of the absolute value of the complex number.

Discussion:

Returns the natural logarithm of the absolute value of a complex number.

Complex arithmetic operators

gsl-complex-add Function
Signature:

gsl-complex-add (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The first complex number.

  • b – A <gsl-complex*>. The second complex number.

Values:
  • z – A <gsl-complex*>. The result of adding the two complex numbers.

Discussion:

Returns the sum of two complex numbers.

gsl-complex-sub Function
Signature:

gsl-complex-sub (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The first complex number.

  • b – A <gsl-complex*>. The second complex number.

Values:
  • z – A <gsl-complex*>. The result of subtracting the second complex number from the first.

Discussion:

Returns the difference between two complex numbers.

gsl-complex-mul Function
Signature:

gsl-complex-mul (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The first complex number.

  • b – A <gsl-complex*>. The second complex number.

Values:
  • z – A <gsl-complex*>. The result of multiplying the two complex numbers.

Discussion:

Returns the product of two complex numbers.

gsl-complex-div Function
Signature:

gsl-complex-div (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The first complex number.

  • b – A <gsl-complex*>. The second complex number.

Values:
  • z – A <gsl-complex*>. The result of dividing the first complex number by the second.

Discussion:

Returns the quotient of two complex numbers.

gsl-complex-add-real Function
Signature:

gsl-complex-add-real (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The real number to add to the complex number.

Values:
  • z – A <gsl-complex*>. The result of adding the real number to the complex number.

Discussion:

Returns the sum of a complex number and a real number.

gsl-complex-sub-real Function
Signature:

gsl-complex-sub-real (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The real number to subtract from the complex number.

Values:
  • z – A <gsl-complex*>. The result of subtracting the real number from the complex number.

Discussion:

Returns the difference between a complex number and a real number.

gsl-complex-mul-real Function
Signature:

gsl-complex-mul-real (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The real number to multiply the complex number by.

Values:
  • z – A <gsl-complex*>. The result of multiplying the complex number by the real number.

Discussion:

Returns the product of a complex number and a real number.

gsl-complex-div-real Function
Signature:

gsl-complex-div-real (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The real number to divide the complex number by.

Values:
  • z – A <gsl-complex*>. The result of dividing the complex number by the real number.

Discussion:

Returns the quotient of a complex number and a real number.

gsl-complex-add-imag Function
Signature:

gsl-complex-add-imag (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The imaginary number to add to the complex number.

Values:
  • z – A <gsl-complex*>. The result of adding the imaginary number to the complex number.

Discussion:

Returns the sum of a complex number and an imaginary number.

gsl-complex-sub-imag Function
Signature:

gsl-complex-sub-imag (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The imaginary number to subtract from the complex number.

Values:
  • z – A <gsl-complex*>. The result of subtracting the imaginary number from the complex number.

Discussion:

Returns the difference between a complex number and an imaginary number.

gsl-complex-mul-imag Function
Signature:

gsl-complex-mul-imag (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The imaginary number to multiply the complex number by.

Values:
  • z – A <gsl-complex*>. The result of multiplying the complex number by the imaginary number.

Discussion:

Returns the product of a complex number and an imaginary number.

gsl-complex-div-imag Function
Signature:

gsl-complex-div-imag (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

  • b – A <c-double>. The imaginary number to divide the complex number by.

Values:
  • z – A <gsl-complex*>. The result of dividing the complex number by the imaginary number.

Discussion:

Returns the quotient of a complex number and an imaginary number.

gsl-complex-conjugate Function
Signature:

gsl-complex-conjugate (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of conjugating the complex number.

Discussion:

Returns the complex conjugate of a complex number.

gsl-complex-inverse Function
Signature:

gsl-complex-inverse (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of inverting the complex number.

Discussion:

Returns the inverse of a complex number.

gsl-complex-negative Function
Signature:

gsl-complex-negative (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of negating the complex number.

Discussion:

Returns the negative of a complex number.

Elementary Complex

gsl-complex-sqrt Function
Signature:

gsl-complex-sqrt (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the square root of the complex number.

Discussion:

Returns the square root of a complex number.

gsl-complex-exp Function
Signature:

gsl-complex-exp (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the exponential of the complex number.

Discussion:

Returns the exponential of a complex number.

gsl-complex-log Function
Signature:

gsl-complex-log (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the natural logarithm of the complex number.

Discussion:

Returns the natural logarithm of a complex number.

gsl-complex-log10 Function
Signature:

gsl-complex-log10 (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the base-10 logarithm of the complex number.

Discussion:

Returns the base-10 logarithm of a complex number.

gsl-complex-sqrt-real Function
Signature:

gsl-complex-sqrt-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the square root of the real number.

Discussion:

Returns the square root of a real number as a complex number.

gsl-complex-pow Function
Signature:

gsl-complex-pow (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The base.

  • b – A <gsl-complex*>. The exponent.

Values:
  • z – A <gsl-complex*>. The result of raising the base to the power of the exponent.

Discussion:

Returns the result of raising a complex number to the power of another complex number.

gsl-complex-pow-real Function
Signature:

gsl-complex-pow-real (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The base.

  • b – A <c-double>. The exponent.

Values:
  • z – A <gsl-complex*>. The result of raising the base to the power of the exponent.

Discussion:

Returns the result of raising a complex number to the power of a real number.

gsl-complex-log-b Function
Signature:

gsl-complex-log-b (a b) => (z)

Parameters:
  • a – A <gsl-complex*>. The number.

  • b – A <gsl-complex*>. The base.

Values:
  • z – A <gsl-complex*>. The result of taking the logarithm of the number with the given base.

Discussion:

Returns the logarithm of a complex number with the given base.

Complex trigonometric

gsl-complex-sin Function
Signature:

gsl-complex-sin (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the sine of the complex number.

Discussion:

Returns the sine of a complex number.

gsl-complex-cos Function
Signature:

gsl-complex-cos (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the cosine of the complex number.

Discussion:

Returns the cosine of a complex number.

gsl-complex-tan Function
Signature:

gsl-complex-tan (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the tangent of the complex number.

Discussion:

Returns the tangent of a complex number.

gsl-complex-sec Function
Signature:

gsl-complex-sec (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the secant of the complex number.

Discussion:

Returns the secant of a complex number.

gsl-complex-csc Function
Signature:

gsl-complex-csc (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the cosecant of the complex number.

Discussion:

Returns the cosecant of a complex number.

gsl-complex-cot Function
Signature:

gsl-complex-cot (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the cotangent of the complex number.

Discussion:

Returns the cotangent of a complex number.

Inverse trigonometric

gsl-complex-arcsin Function
Signature:

gsl-complex-arcsin (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arcsine of the complex number.

Discussion:

Returns the arcsine of a complex number.

gsl-complex-arccos Function
Signature:

gsl-complex-arccos (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccosine of the complex number.

Discussion:

Returns the arccosine of a complex number.

gsl-complex-arctan Function
Signature:

gsl-complex-arctan (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arctangent of the complex number.

Discussion:

Returns the arctangent of a complex number.

gsl-complex-arcsec Function
Signature:

gsl-complex-arcsec (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arcsecant of the complex number.

Discussion:

Returns the arcsecant of a complex number.

gsl-complex-arccsc Function
Signature:

gsl-complex-arccsc (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccosecant of the complex number.

Discussion:

Returns the arccosecant of a complex number.

gsl-complex-arccot Function
Signature:

gsl-complex-arccot (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccotangent of the complex number.

Discussion:

Returns the arccotangent of a complex number.

gsl-complex-arcsin-real Function
Signature:

gsl-complex-arcsin-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the arcsine of the real number.

Discussion:

Returns the arcsine of a real number as a complex number.

gsl-complex-arccos-real Function
Signature:

gsl-complex-arccos-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccosine of the real number.

Discussion:

Returns the arccosine of a real number as a complex number.

gsl-complex-arcsec-real Function
Signature:

gsl-complex-arcsec-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the arcsecant of the real number.

Discussion:

Returns the arcsecant of a real number as a complex number.

gsl-complex-arccsc-real Function
Signature:

gsl-complex-arccsc-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccosecant of the real number.

Discussion:

Returns the arccosecant of a real number as a complex number.

gsl-complex-arccosh-real Function
Signature:

gsl-complex-arccosh-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccosh of the real number.

Discussion:

Returns the arccosh of a real number as a complex number.

gsl-complex-arctanh-real Function
Signature:

gsl-complex-arctanh-real (a) => (z)

Parameters:
  • a – A <c-double>. The real number.

Values:
  • z – A <gsl-complex*>. The result of taking the arctanh of the real number.

Discussion:

Returns the arctanh of a real number as a complex number.

Complex hyperbolic

gsl-complex-sinh Function
Signature:

gsl-complex-sinh (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the hyperbolic sine of the complex number.

Discussion:

Returns the hyperbolic sine of a complex number.

gsl-complex-cosh Function
Signature:

gsl-complex-cosh (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the hyperbolic cosine of the complex number.

Discussion:

Returns the hyperbolic cosine of a complex number.

gsl-complex-tanh Function
Signature:

gsl-complex-tanh (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the hyperbolic tangent of the complex number.

Discussion:

Returns the hyperbolic tangent of a complex number.

gsl-complex-sech Function
Signature:

gsl-complex-sech (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the hyperbolic secant of the complex number.

Discussion:

Returns the hyperbolic secant of a complex number.

gsl-complex-csch Function
Signature:

gsl-complex-csch (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the hyperbolic cosecant of the complex number.

Discussion:

Returns the hyperbolic cosecant of a complex number.

gsl-complex-coth Function
Signature:

gsl-complex-coth (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the hyperbolic cotangent of the complex number.

Discussion:

Returns the hyperbolic cotangent of a complex number.

Inverse complex hyperbolic

gsl-complex-arcsinh Function
Signature:

gsl-complex-arcsinh (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arcsinh of the complex number.

Discussion:

Returns the arcsinh of a complex number.

gsl-complex-arccosh Function
Signature:

gsl-complex-arccosh (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccosh of the complex number.

Discussion:

Returns the arccosh of a complex number.

gsl-complex-arctanh Function
Signature:

gsl-complex-arctanh (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arctanh of the complex number.

Discussion:

Returns the arctanh of a complex number.

gsl-complex-arcsech Function
Signature:

gsl-complex-arcsech (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arcsech of the complex number.

Discussion:

Returns the arcsech of a complex number.

gsl-complex-arccsch Function
Signature:

gsl-complex-arccsch (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccsch of the complex number.

Discussion:

Returns the arccsch of a complex number.

gsl-complex-arccoth Function
Signature:

gsl-complex-arccoth (a) => (z)

Parameters:
  • a – A <gsl-complex*>. The complex number.

Values:
  • z – A <gsl-complex*>. The result of taking the arccoth of the complex number.

Discussion:

Returns the arccoth of a complex number.