This package helps to automate the printing of values with errors in brackets.
This is a very simple but yet useful package which helps to generate strings with values and their corresponding error followed in brackets, e. g., 23.56(12)(30)
stands for 23.56 ± 0.12 ± 0.30
.
This is common notation in science and this package provides a function to generate these strings.
The reading is the following: the error denoted with 0.345(56) = 0.345 ± 0.56
or 1234567890(123) = 1234567890 ± 123
.
The errors are always rounded with ceil
while the value is rounded with round
. This rule is a usual conservative case for rounding errors.
By default the errors will have 2 digits in the brackets. See next section for more explanations.
This function is mainly written for float-like types as Float64
.
There is only one function exported: bracederror
.
The usage is explained in its docstring.
julia> bracederror(123.456, 0.123)
"123.46(13)"
julia> bracederror(123.456, 0.00123)
"123.4560(13)"
julia> bracederror(123.456, 123456)
"123(130000)"
You can provide two or more errors.
julia> bracederror(123.456, 123456, 0.0034)
"123.4560(1300000000)(34)"
julia> bracederror(123.456, 0.123456, 0.0034)
"123.4560(1300)(34)"
julia> bracederror(1.23456, 0.1, 0.23, 0.45, 0.56)
"1.23(10)(23)(45)(57)"
With some keywords you can customize the output.
dec::Int = 2
: number of decimals to round the errors tosuff::NTuple{String} = ("", ...)
: optional suffix after the brackets (Tuple can be omitted when using with only one error)bracket::NTuple{Symbol} = (:r, ...)
: type of the brackets (Tuple can be omitted when using with only one error)
bracket
can take the values: [:a, :l, :s, :r, :c, :_, :^]
(angular, line, square, round, curly, subscript, superscript) which correspond to ["<>", "||", "[]", "()", "{}", "_{}", "^{}"]
.
The last two are useful for LaTeX output.
However, note that this is not a common way of printing the errors.
In such cases one usually prints the real error like in this example:
julia> bracederror(123.456, 0.123456, 0.0034; bracket=:s)
"123.4560[1300](34)"
julia> bracederror(123.456, 0.123456, 0.0034; suff2="_\\inf")
"123.4560(1300)(34)_\\inf"
julia> bracederror(123.456, 0.123456, 0.0034; dec=1)"123.456(200)(4)"
Due to the fact that BracedErrors
by default does not export it. It is however defined and can be used by importing it like this:
julia> import BracedErrors: ±
julia>0.234 ± 0.00056
"0.23400(56)"
julia>0.234 ± (0.00056, 0.45)
"0.23400(56)(45000)"
julia>±(0.234, 0.00056, 0.45; bracket =(:r,:s))
"0.23400(56)[45000]"
By using this infix operator you gain even more convenience in error printing in strings like "$(val ± err)"
and so on.
I have written this package during the hackathon at juliacon 2018 and this is the first official package. I have tried to test it on different cases but it is still very early stage. Please use it with care and any help is welcome.