Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library for Physical and mathematic constants and basic conversions in c# .net [closed]

Tags:

c#

.net

I saw we can get the value of PI thanks to Math.PI in C#.

Do you know if exists a library or a package for getting rounded values for other famous constants, like for example, Avogadroo, Kelvin, Planck, Coulombs, golden number, Newton constant?

It would be very greate if we could do some simple convertions.

In other world: a light moment.js for sciences, it would save a lot of time to a lot of people.

like image 422
lambdaDev Avatar asked Feb 03 '16 08:02

lambdaDev


2 Answers

As Him has already mentioned you can use const keyword for storing the constant values. You can also see this article:

// 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;

// Avogadro Number. Units  1/mol 
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;

// Solar Radius. Units cm
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;

It would be great if it would exists a a package, a library or a native class for that

As such there is no such library which you can use or a native class. The best is to include the above constants in a separate class and then use it.

like image 168
Rahul Tripathi Avatar answered Sep 18 '22 22:09

Rahul Tripathi


You can use the const-keyword for this:

class MyClass {
    public const double KELVIN = -273.15;
}

Now access it using MyClass.KELVIN.

However depending on the accuracy you need for your calculations you may need different datatypes, e.g. decimal, float or double.

There does not exist a library for those constants because those constantns share very different aspects and noone so far as considered them to be contained in one library. However you may do it by adding them to a class and publish it on GitHub.

like image 32
MakePeaceGreatAgain Avatar answered Sep 19 '22 22:09

MakePeaceGreatAgain