sum(large:small:)
The sum a + b
represented as an implicit sum head + tail
.
static func sum<T>(large a: T, small b: T) -> (head: T, tail: T) where T : Real
Parameters
head
is the correctly rounded value of a + b
. tail
is the error from that computation rounded to the closest representable value.
Unlike Augmented.product(a, b)
, the rounding error of a sum can never underflow. However, it may not be exactly representable when a
and b
differ widely in magnitude.
This operation is sometimes called “fastTwoSum”.
Preconditions:
large.magnitude
must not be smaller thansmall.magnitude
. They may be equal, or one or both may beNaN
. This precondition is only enforced in debug builds.
Edge Cases:
head
is always the IEEE 754 suma + b
.If
head
is not finite,tail
is unspecified and should not be interpreted as having any meaning (it may beNaN
orinfinity
).
Postconditions:
If
head
is normal, thenabs(tail) < head.ulp
. Assuming IEEE 754 default rounding,abs(tail) <= head.ulp/2
.