This probably shouldn't even exist
Author tbeason
3 Stars
Updated Last
2 Years Ago
Started In
February 2020


Lifecycle Build Status

Julia core maintainers suggested in this 2015 original issue that a plusminus function was not worthy of inclusion in Base Julia, much to the disappointment of statisticians everywhere.

Fear not!

This package implements the plus-minus function (and that's it!).

plusminus(x::Number,y::Number) = (x-y,x+y)

±(x,y) = plusminus(x,y)     # thats \pm followed by TAB

2 ± 1       # returns (1,3)

The convention I use here is for the x-y to return first and x+y second. Because the output is a tuple, you can apply reverse to it to get the items in the other order. Alternatively, use direct assignment: minusitem,plusitem = 2 ± 1.

The package is registered, so can be added with ]add PlusMinus and available for use after using PlusMinus.

Broadcasting is automatic because Julia rocks.

(±).(1:3,1) == [(i-1,i+1) for i in 1:3]

Flawlessly works with rationals as well.

julia> 2//5 ± 1//2
(-1//10, 9//10)