// -*- mode: c++ -*-

/* Library libcerf:
 *   A self-contained numeric library that provides an efficient and accurate implementation
 *   of complex error functions, along with Dawson, Faddeeva, and Voigt functions.
 *
 * File cerf:
 *   C++ header.
 *   This is the only C++ code in the project.
 *   It is not compiled within libcerf.
 *
 *
 * Copyright:
 *   (C) 2012 Massachusetts Institute of Technology
 *   (C) 2013 Forschungszentrum Jülich GmbH
 *
 * Licence:
 *   Permission is hereby granted, free of charge, to any person obtaining
 *   a copy of this software and associated documentation files (the
 *   "Software"), to deal in the Software without restriction, including
 *   without limitation the rights to use, copy, modify, merge, publish,
 *   distribute, sublicense, and/or sell copies of the Software, and to
 *   permit persons to whom the Software is furnished to do so, subject to
 *   the following conditions:
 *
 *   The above copyright notice and this permission notice shall be
 *   included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *   Steven G. Johnson, Massachusetts Institute of Technology, 2012, core author
 *   Joachim Wuttke, Forschungszentrum Jülich, 2013, package maintainer
 *
 * Website:
 *   http://apps.jcns.fz-juelich.de/libcerf
 *
 * Revision history:
 *   ../CHANGELOG
 *
 * Man pages:
 *   w_of_z(3), dawson(3), voigt(3), cerf(3), erfcx(3), erfi(3)
 */


#include <cerf_real.h> // declares real functions, and defines the EXPORT macro
#include <cerf_ptr.h>  // declares pointerized wrappers of complex functions
#include <complex>

// The following functions overload functions declared in cerf.h,
// substituting the C++ type complex<double> for the C type double _Complex.

//! compute w(z) = exp(-z^2) erfc(-iz), Faddeeva's scaled complex error function
EXPORT std::complex<double> w_of_z(std::complex<double> z) {
    std::complex<double> ret;
    p_w_of_z((void*)&z, (void*)&ret);
    return ret;
}

//! compute erf(z), the error function of complex arguments
EXPORT std::complex<double> cerf(std::complex<double> z) {
    std::complex<double> ret;
    p_cerf((void*)&z, (void*)&ret);
    return ret;
}

//! compute erfc(z) = 1 - erf(z), the complementary error function
EXPORT std::complex<double> cerfc(std::complex<double> z) {
    std::complex<double> ret;
    p_cerfc((void*)&z, (void*)&ret);
    return ret;
}

//! Compute erfcx(z) = exp(z^2) erfc(z), an underflow-compensated version of erfc.
EXPORT std::complex<double> cerfcx(std::complex<double> z) {
    std::complex<double> ret;
    p_cerfcx((void*)&z, (void*)&ret);
    return ret;
}

//! compute erfi(z) = -i erf(iz), the imaginary error function
EXPORT std::complex<double> cerfi(std::complex<double> z) {
    std::complex<double> ret;
    p_cerfi((void*)&z, (void*)&ret);
    return ret;
}

//! compute dawson(z) = sqrt(pi)/2 * exp(-z^2) * erfi(z), Dawson's integral
EXPORT std::complex<double> cdawson(std::complex<double> z) {
    std::complex<double> ret;
    p_cdawson((void*)&z, (void*)&ret);
    return ret;
}
