Skip to content

ir2-lab/value-with-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

value-with-error

A C++ class for rounding and printing values with errors as obtained e.g. in experimental measurements.

The following code

#include <value_with_error.h>

using namespace std;

int main()
{
    double f = 1.234e-9;
    double df = 0.123e-9;
    value_with_error ve(f,df);
    std::cout << f << " ± " df << " = " << ve << std::endl;
    return 0;
}

produces the output:

1.234e-9 ± 0.123e-9 = (1.23 ± 0.12)×10⁻⁹

There are options for controlling:

  • the number of significant error digits (default=2)
  • the number format (fixed, scientific)
  • the printing format using "±", e.g. 1.2 ± 0.1, or parenthesis, 1.2(1).

See the comments in the code for details.

The class is contained in a single header file.

About

A C++ class for rounding and printing values with errors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors