From ff56b6965e424a0ac4acd44a7b8c0303724f5a80 Mon Sep 17 00:00:00 2001 From: Pawel Troka Date: Thu, 16 Mar 2017 23:02:07 +0100 Subject: [PATCH] Recreated function logGamma (issue #12) --- .../Functions/SpecialFunctions.cs | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Computator.NET.Core/Functions/SpecialFunctions.cs b/Computator.NET.Core/Functions/SpecialFunctions.cs index 476e4b6..26fc9a9 100644 --- a/Computator.NET.Core/Functions/SpecialFunctions.cs +++ b/Computator.NET.Core/Functions/SpecialFunctions.cs @@ -198,22 +198,19 @@ public static System.Numerics.Complex Γ(System.Numerics.Complex z) return cmplxFromMeta(Meta.Numerics.Functions.AdvancedComplexMath.Gamma(cmplxToMeta(z))); } - /* - public static Complex logGamma(Complex z) + + public static System.Numerics.Complex logGamma(System.Numerics.Complex z) { - gsl_sf_result lnr = new gsl_sf_result(), arg = new gsl_sf_result(); - gsl_sf_lngamma_complex_e(z.Real, z.Imaginary, out lnr, out arg); - return (lnr.val + arg.val*Complex.ImaginaryOne); + if (z.Real < 0) return double.NaN; + return cmplxFromMeta(Meta.Numerics.Functions.AdvancedComplexMath.LogGamma(cmplxToMeta(z))); } - public static Complex logΓ(Complex z) + public static System.Numerics.Complex logΓ(System.Numerics.Complex z) { - gsl_sf_result lnr = new gsl_sf_result(), arg = new gsl_sf_result(); - gsl_sf_lngamma_complex_e(z.Real, z.Imaginary, out lnr, out arg); - return (lnr.val + arg.val*Complex.ImaginaryOne); + if (z.Real < 0) return double.NaN; + return cmplxFromMeta(Meta.Numerics.Functions.AdvancedComplexMath.LogGamma(cmplxToMeta(z))); } - */ - + [System.Runtime.InteropServices.DllImport(Computator.NET.DataTypes.GslConfig.GslDllName, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] private static extern int gsl_sf_lngamma_complex_e(double zr, double zi, out gsl_sf_result lnr, @@ -2454,21 +2451,17 @@ public static System.Numerics.Complex Γ(System.Numerics.Complex z) return cmplxFromMeta(Meta.Numerics.Functions.AdvancedComplexMath.Gamma(cmplxToMeta(z))); } - /* - public static Complex logGamma(Complex z) + public static System.Numerics.Complex logGamma(System.Numerics.Complex z) { - gsl_sf_result lnr = new gsl_sf_result(), arg = new gsl_sf_result(); - gsl_sf_lngamma_complex_e(z.Real, z.Imaginary, out lnr, out arg); - return (lnr.val + arg.val*Complex.ImaginaryOne); + if (z.Real < 0) return double.NaN; + return cmplxFromMeta(Meta.Numerics.Functions.AdvancedComplexMath.LogGamma(cmplxToMeta(z))); } - public static Complex logΓ(Complex z) + public static System.Numerics.Complex logΓ(System.Numerics.Complex z) { - gsl_sf_result lnr = new gsl_sf_result(), arg = new gsl_sf_result(); - gsl_sf_lngamma_complex_e(z.Real, z.Imaginary, out lnr, out arg); - return (lnr.val + arg.val*Complex.ImaginaryOne); + if (z.Real < 0) return double.NaN; + return cmplxFromMeta(Meta.Numerics.Functions.AdvancedComplexMath.LogGamma(cmplxToMeta(z))); } - */ [System.Runtime.InteropServices.DllImport(Computator.NET.DataTypes.GslConfig.GslDllName, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]