13,257,666 members (79,740 online)
alternative version

#### Stats

70.5K views
26 bookmarked
Posted 15 Sep 2005

# Special Function(s) for C#

, 15 Sep 2005
 Rate this:

## Introduction

This class contains physical constants and special functions not found in the System.Math class (C# port of the Cephes math library).

## Constants

// Physical Constants in cgs Units

// Boltzman Constant. Units erg/deg(K)
public const double BOLTZMAN = 1.3807e-16;

// Elementary Charge. Units statcoulomb
public const double ECHARGE = 4.8032e-10;

// Electron Mass. Units g
public const double EMASS = 9.1095e-28;

// Proton Mass. Units g
public const double PMASS = 1.6726e-24;

// Gravitational Constant. Units dyne-cm^2/g^2
public const double GRAV = 6.6720e-08;

// Planck constant. Units erg-sec
public const double PLANCK = 6.6262e-27;

// Speed of Light in a Vacuum. Units cm/sec
public const double LIGHTSPEED = 2.9979e10;

// Stefan-Boltzman Constant. Units erg/cm^2-sec-deg^4
public const double STEFANBOLTZ = 5.6703e-5;

public const double AVOGADRO = 6.0220e23;

// Gas Constant. Units erg/deg-mol
public const double GASCONSTANT = 8.3144e07;

// Gravitational Acceleration at the Earths surface. Units cm/sec^2
public const double GRAVACC = 980.67;

// Solar Mass. Units g
public const double SOLARMASS = 1.99e33;

public const double SOLARRADIUS = 6.96e10;

// Solar Luminosity. Units erg/sec
public const double SOLARLUM = 3.90e33;

// Solar Flux. Units erg/cm^2-sec
public const double SOLARFLUX = 6.41e10;

// Astronomical Unit (radius of the Earth's orbit). Units cm
public const double AU = 1.50e13;

## Methods

/// Returns the base 10 logarithm of the specified number.
public static double log10(double x);

/// Returns the hyperbolic cosine of the specified number.
public static double cosh(double x);

/// Returns the hyperbolic sine of the specified number.
public static double sinh(double x);

/// Returns the hyperbolic tangent of the specified number.
public static double tanh(double x);

/// Returns the hyperbolic arc cosine of the specified number.
public static double acosh(double x);

/// Returns the hyperbolic arc sine of the specified number.
public static double asinh(double xx);

/// Returns the hyperbolic arc tangent of the specified number.
public static double atanh(double x);

/// Returns the Bessel function of order 0 of the specified number.
public static double j0(double x);

/// Returns the Bessel function of order 1 of the specified number.
public static double j1(double x);

/// Returns the Bessel function of order n of the specified number.
public static double jn(int n, double x);

/// Returns the Bessel function of the second kind,
/// of order 0 of the specified number.
public static double y0(double x);

/// Returns the Bessel function of the second kind,
/// of order 1 of the specified number.
public static double y1(double x);

/// Returns the Bessel function of the second kind,
/// of order n of the specified number.
public static double yn(int n, double x);

/// Returns the factorial of the specified number.
public static double fac(double x);

/// Returns the factorial of the specified number.
public static int fac(int j);

/// Returns the gamma function of the specified number.
public static double gamma(double x);

/// Return the gamma function computed by Stirling's formula.
private static double stirf(double x);

/// Returns the complemented incomplete gamma function.
public static double igamc(double a, double x);

/// Returns the incomplete gamma function.
public static double igam(double a, double x);

/// Returns the chi-square function (left hand tail).
public static double chisq(double df, double x);

/// Returns the chi-square function (right hand tail).
public static double chisqc(double df, double x);

/// Returns the sum of the first k terms of the Poisson distribution.
public static double poisson(int k, double x);

/// Returns the sum of the terms k+1 to infinity of the Poisson distribution.
public static double poissonc(int k, double x);

/// Returns the area under the Gaussian probability density function,
///integrated from minus infinity to a.
public static double normal(double a);

/// Returns the complementary error function of the specified number.
public static double erfc(double a);

/// Returns the error function of the specified number.
public static double erf(double x);

/// Evaluates polynomial of degree N
private static double polevl(double x, double[] coef, int N);

/// Evaluates polynomial of degree N with assumption that coef[N] = 1.0
private static double p1evl(double x, double[] coef, int N);

/// Returns the natural logarithm of gamma function.
public static double lgamma(double x);

/// Returns the incomplete beta function evaluated from zero to xx.
public static double ibeta(double aa, double bb, double xx);

/// Returns the continued fraction expansion #1 for incomplete beta integral.
private static double incbcf(double a, double b, double x);

/// Returns the continued fraction expansion #2 for incomplete beta integral.
private static double incbd(double a, double b, double x);

/// Returns the power series for incomplete beta integral.
/// Use when b*x is small and x not too close to 1.
private static double pseries(double a, double b, double x);

## Outroduction

I hope this will put a smile on someone's face, at least one. :)

## History

• 15th September, 2005: Initial post

## Share

 Software Developer (Senior) Croatia
No Biography provided

## You may also be interested in...

 First Prev Next
 I think I love you Member 1091072416-Sep-15 8:41 Member 10910724 16-Sep-15 8:41
 Great job joni50para21-Nov-14 3:48 joni50para 21-Nov-14 3:48
 Complementary Incomplete Gamma Functions Member 105118748-Jan-14 11:18 Member 10511874 8-Jan-14 11:18
 Thank you. Member 1041310819-Nov-13 19:52 Member 10413108 19-Nov-13 19:52
 Thank you! Jeff Manning24-Jan-13 15:06 Jeff Manning 24-Jan-13 15:06
 Thanks a lot Member 341649812-Jan-13 4:41 Member 3416498 12-Jan-13 4:41
 Thanks a lot for putting it together. Just one observation, it would be better to take constant arrays out of functions bodies and make them static. I am getting up to 6 times speed increase with this simple modification.
 Awesome !!! ty very much! Member 822634013-Dec-12 3:23 Member 8226340 13-Dec-12 3:23
 Copied functions iliyapolak5-Apr-12 4:01 iliyapolak 5-Apr-12 4:01
 Re: Copied functions Jay Lemmon4-Jan-14 12:26 Jay Lemmon 4-Jan-14 12:26
 MACHEP agelospanagiotakis3-Oct-11 14:39 agelospanagiotakis 3-Oct-11 14:39
 Licensing Member 10990310-Aug-09 7:02 Member 109903 10-Aug-09 7:02
 Re: Licensing Member 816281415-Aug-11 12:12 Member 8162814 15-Aug-11 12:12
 Re: Licensing Member 816368815-Aug-11 22:12 Member 8163688 15-Aug-11 22:12
 Ah, I could kiss you!!! Member 40338572-Apr-08 1:10 Member 4033857 2-Apr-08 1:10
 Good work ram kumar 20212-Sep-07 23:46 ram kumar 2021 2-Sep-07 23:46
 Good work! Desmond McCarter17-May-07 19:41 Desmond McCarter 17-May-07 19:41
 Re: Good work! a26gen11-Jun-07 22:54 a26gen 11-Jun-07 22:54
 fantastic rabbithacking12-Apr-07 11:40 rabbithacking 12-Apr-07 11:40
 Strange units mav.northwind15-Sep-05 12:40 mav.northwind 15-Sep-05 12:40
 Re: Strange units Miroslav Stampar15-Sep-05 23:49 Miroslav Stampar 15-Sep-05 23:49
 Neat, but... Keith Farmer15-Sep-05 9:15 Keith Farmer 15-Sep-05 9:15
 Re: Neat, but... Herbert Sauro5-Nov-05 9:59 Herbert Sauro 5-Nov-05 9:59
 Re: Neat, but... Keith Farmer5-Nov-05 11:28 Keith Farmer 5-Nov-05 11:28
 Last Visit: 31-Dec-99 19:00     Last Update: 23-Nov-17 9:11 Refresh 1