Skip to content

Commit

Permalink
Prep for 1.1 release
Browse files Browse the repository at this point in the history
Added additional C/C++ detection macro
  • Loading branch information
DrGrafil committed May 2, 2018
1 parent 3e30090 commit 60ffc18
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
21 changes: 14 additions & 7 deletions NISTConst/NISTConst.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* NISTConst 1.0.0
* NISTConst 1.1.0
* A constants library for physics and chemistry using data from the
* National Institute of Standards and Technology (NIST).
*
Expand Down Expand Up @@ -44,7 +44,7 @@
///
/// @author Elliot Grafil (Metex)
/// @date 8/9/17
/// @version 1.0.1
/// @version 1.1.0


//=================================
Expand Down Expand Up @@ -315,14 +315,21 @@
/// @defgroup NISTConst-Silicon Silicon
/// @ingroup NISTConst-X-ray


// MACRO Definitions
#ifdef NISTCONST_PRECXX11
//=================================
// MACRO Definitions
#ifdef __cplusplus //Check if C++
#ifdef NISTCONST_PRECXX11
#define NISTCONST_CONSTANT static const double
#else
#define NISTCONST_CONSTANT static constexpr double
#endif
#else //For C
#define NISTCONST_CONSTANT static const double
#else
#define NISTCONST_CONSTANT static constexpr double
#endif

//=================================
// Constaant Definitions

namespace NISTConst
{

Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ NISTConst is a header-only library, and therfore does not need to be compiled. A

### Additional Options

By default NISTConst doesn't set the uncertainties associated with all the constants. To add these uncertainties to your program you need to `#define NISTCONST_UNCERTAINTY` before you include NISTConst. All uncertainties are accessed by just adding `Uncertainty` to a the variable name. For example the uncertainty in the planck constant, `PlanckConstant`, is simply `PlanckConstantUncertainty`.
By default NISTConst doesn't set the uncertainties associated with all the constants. To add these uncertainties to your program you need to add `#define NISTCONST_UNCERTAINTY` before you include NISTConst. All uncertainties are accessed by just adding `Uncertainty` to a the variable name. For example the uncertainty in the planck constant, `PlanckConstant`, is simply `PlanckConstantUncertainty`.

NISTConst also includes a list of common aliases to all the constants like `c` for speed of light. To add these aliases to your program you need to `#define NISTCONST_COMMON_SYMBOLS_NAMES` before you include NISTConst. These are seperated out since there are multiple one letter variable definitions. This can result in variable name collisions with existing code if you decide to make all symbols in NISTConst namespace visible without adding the namespace prefix via `using namespace NISTConst;`.
NISTConst also includes a list of common aliases to all the constants like `c` for speed of light. To add these aliases to your program you need to add `#define NISTCONST_COMMON_SYMBOLS_NAMES` before you include NISTConst. These are seperated out since there are multiple one letter variable definitions. This can result in variable name collisions with existing code if you decide to make all symbols in NISTConst namespace visible without adding the namespace prefix via `using namespace NISTConst;`.

NISTConst by default defines variables as `static constexpr double` for C++ which wont compile on older compilers. To enable the header to compile on C++98/C++C03 you need to add `#define NISTCONST_PRECXX11` before you include NISTConst.
## Example Usage

```cpp
#define NISTCONST_UNCERTAINTY // To include uncertainties
#define NISTCONST_COMMON_SYMBOLS_NAMES // Common symbols and names for constants.
#define NISTCONST_PRECXX11 //
#include <NISTConst/NISTConst.hpp>

//Calculates the mass defect, the difference between the mass of the atom
//and the sum of the masses of its parts in unified atomic mass units.
double MassDefectInu(int const atomicNumber, int const massNumber, double massAtom)
double MassDefectInu(const int atomicNumber, const int massNumber, const double massAtom)
{
double protonMass = atomicNumber * NISTConst::protonMassInu;
double electronMass = atomicNumber * NISTConst::electronMassInu;
double neutronMass = (massNumber - atomicNumber) * NISTConst::neutronMassInu;
const double protonMass = atomicNumber * NISTConst::protonMassInu;
const double electronMass = atomicNumber * NISTConst::electronMassInu;
const double neutronMass = (massNumber - atomicNumber) * NISTConst::neutronMassInu;

return protonMass + electronMass + neutronMass - massAtom;
}
Expand All @@ -58,7 +60,7 @@ double MassDefectInu(int const atomicNumber, int const massNumber, double massAt
| 1.007276466879 u | NISTConst from NIST/CODATA 2014 |
| 1.007276466879 u | Wikipedia |
| 1.007276466812 u | Google |
| 1.007276466583 u | Latest value from ["High-Precision Measurement of the Protons Atomic Mass"](https://doi.org/10.1103/PhysRevLett.119.033001) |
| 1.007276466583 u | Latest value from ["High-Precision Measurement of the Protons Atomic Mass"](https://doi.org/10.1103/PhysRevLett.119.033001) |
The latest value will probably be adopted by both google and wikipedia in the near future.
Expand All @@ -69,6 +71,22 @@ double MassDefectInu(int const atomicNumber, int const massNumber, double massAt
---
## Release notes
### [NISTConst 1.1.0](https://github.com/Metex/NISTConst/releases/latest)
#### Features:
- Constants are defined as static constexpr for >C++11 compilers
- Added `#define NISTCONST_PRECXX11` macro for older compilers.
- Macro to detect C vs C++ is compiling
#### Improvements:
- Added additional Install instructions to readme.
- Detabifyed the header file.
#### Fixes:
- Fixed bug in README code.
---
## Release notes
### [NISTConst 1.0.0](https://github.com/Metex/NISTConst/releases/latest)
#### Features:
- Completed verification.
Expand Down

0 comments on commit 60ffc18

Please sign in to comment.