Skip to content

Commit

Permalink
Adding CODATA2014.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlconlin committed Sep 13, 2018
1 parent f32e186 commit 215d3e0
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 8 deletions.
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
r constants
# constants
This repository contains a collection of mathematical and physical constants.

**Note:** For the constants given here, their values are actually given in three places in this repository:

1. Here in the `README.md` file,
2. In the header file that defines the value for C++, and
3. In the files used to test/verify the value.
While every effort is made to ensure that each of these values are the same, inconsistencies may appear. If discovered, please [file an issue](https://github.com/njoy/constants/issues).

## Mathematical Constants
The (short) list of mathematical constants was taken from [Wikipedia:Mathematical constant](https://en.wikipedia.org/wiki/Mathematical_constant). While there are many more constants given there, we have limited this initially to the [Basic mathematical constants](https://en.wikipedia.org/wiki/Mathematical_constant#Basic_mathematical_constants).
Expand All @@ -17,8 +11,15 @@ The (short) list of mathematical constants was taken from [Wikipedia:Mathematica
| Euler's number (e) | `e` | `2.718281828459045` | [http://mathworld.wolfram.com/e.html]() | 2018-09-13 |
| Pythagoras' constant (√2) | `root2` | `1.414213562373095` | [http://mathworld.wolfram.com/PythagorassConstant.html]() | 2018-09-13 |

### Using mathematical constants
**Note:** For the mathematical constants, their values are actually given in three places in this repository:

1. Here in the `README.md` file,
2. In the header file that defines the value for C++, and
3. In the `math.test.cpp` file used to test/verify the values.
While every effort is made to ensure that each of these values are the same, inconsistencies may appear. If discovered, please [file an issue](https://github.com/njoy/constants/issues).

### Using mathematical constants
Here is an example of how the mathematical constants can be used.
```cpp
#include "constants/math.hpp"

Expand All @@ -27,6 +28,29 @@ double r{1.0};
auto area = njoy::constants::math::pi*r**2;
```
## Physical Constants
Unlike mathematical constants, physical constants can change based on the current understanding and measurement capabilities of physics. Thus we can have different versions of the constants.
The worldwide standard for the physical constants is maintained by [Committee on Data of the International Council for Science (CODATA)](https://www.codata.org). We have taken our physical constant values from their publication. For information about what values are maintained in this repository, see the respective README files:
- [CODATA2014](src/constants/physics/CODATA2014/README.md)
- CODATA2018 This should be published in 2019. We will update the repository after the publication.
For each CODATA release, we provide two maps; one for the data values and one for their associated uncertainty. The keys are the same in both maps. There are some physical constants that are defined to be exact (e.g., the speed of light). Their uncertainty, is, therefore, zero.
```cpp
#include "constants/physics/CODATA2014.hpp"
auto CODATA = njoy::constants::CODATA2014;
auto CODATAUncertainty = njoy::constants::CODATA2014Uncertainty;
auto c = CODATA[c];
auto cUncertainty = CODATAUncertainty[c]; // 0.0
auto hbar = CODATA[Planck];
auto hbarUncertainty = CODATAUncertainty[Planck];
```

## A note on floating point arithmetic
Some values of these constants are known to much greater precision than what we have reported here (e.g., `pi` and `e`.) We have limited the number of significant digits in this repository to 16 as anything more would be insignificant in floating point arithmetic.

Expand Down
3 changes: 3 additions & 0 deletions src/constants/physics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef NJOY_CONSTANTS_PHYSICS_HPP
#define NJOY_CONSTANTS_PHYSICS_HPP
#endif // NJOY_CONSTANTS_PHYSICS_HPP
15 changes: 15 additions & 0 deletions src/constants/physics/CODATA.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef NJOY_CONSTANTS_PHYSICS_CODATA_HPP
#define NJOY_CONSTANTS_PHYSICS_CODATA_HPP

namespace njoy{
namespace constants{
namespace physics{

static SpeedOfLight_t{};
static constexpr SpeedOfLight_t c{};
static constexpr SpeedOfLight_t speedOfLight{};

}
} // namespace constants
} // namespace njoy
#endif // NJOY_CONSTANTS_PHYSICS_CODATA_HPP
14 changes: 14 additions & 0 deletions src/constants/physics/CODATA2014.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef NJOY_CONSTANTS_PHYSICS_CODATA2014_HPP
#define NJOY_CONSTANTS_PHYSICS_CODATA2014_HPP

#include "constants/physics/CODATA.hpp"

namespace njoy{
namespace constants{
namespace physics{

}
} // namespace constants
} // namespace njoy
#endif // NJOY_CONSTANTS_PHYSICS_CODATA2014_HPP

Loading

0 comments on commit 215d3e0

Please sign in to comment.