Skip to content

Gem to round numbers using the PDG rounding rules

License

Notifications You must be signed in to change notification settings

AAraKKe/pdground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gem Version

PDGRound

PDGRound allows you to round a number with an uncertainty using the PDG rounding rules.

Installation

Add this line to your application's Gemfile:

gem 'pdground'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pdground

Usage

Pdground provides an easy to use function to round a given number with an uncertainty using the PDG rules. The rule states the following [Sec 5.3]:

The basic rule states that if the three highest order digits of the error lie between 100 and 354, we round to two significant digits. If they lie between 355 and 949, we round to one significant digit. Finally, if they lie between 950 and 999, we round up to 1000 and keep two significant digits. In all cases, the central value is given with a precision that matches that of the error

For example, given the value 12.2135 +- 0.03215 the rounded value reults in 12.214 +- 0.032 while for the value 12.2135 +- 0.06515 the rounded value reults in 12.21 +- 0.07.

Using Pdground in your code it is as simple as doing:

require 'pdground'

value = 12.2135
error = 0.06515
result = PDGRound.round(meas: value, unc: error)
puts "Rounded value: #{result[0]}"
puts "Rounded error: #{result[1]}"
# Rounded value: 12.21
# Rounded error: 0.07 

Contributing

Contributions to this project are only accepted in its GitLab repo If you want to contribute to improve this gem with any bug fix or new feature:

  • First open an issue to discuss the bug or feature
  • Place a merge request referring to the issue once agreed to include it

Tests must be added to ensure maintainability.

License

The gem is available as open source under the terms of the MIT License.

About

Gem to round numbers using the PDG rounding rules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published