Fix sign of exact cancellation in bf16_mulAdd (#53) We were getting it right for e.g. 1x0-0, but not e.g. 1x3-3. Supersedes #52 Signed-off-by: Andrew Waterman <andrew@sifive.com>
diff --git a/source/bf16_mulAdd.c b/source/bf16_mulAdd.c index 20c8793..83ceb1c 100644 --- a/source/bf16_mulAdd.c +++ b/source/bf16_mulAdd.c
@@ -49,10 +49,10 @@ uint_fast8_t roundingMode = softfloat_roundingMode; - /* Add rounding to odd to prevent double rounding, unless the product - * is zero, in which case we know the sum will be exact, and we need - * rounding-mode-specific minus-zero handling. */ - if ( (prod.v << 1) != 0 ) + /* Add rounding to odd to prevent double rounding, unless the sum + * exactly cancels, in which case the sign depends on the original + * rounding mode. */ + if ( ( prod.v ^ f64C.v ) != packToF64UI( 1, 0, 0 ) ) softfloat_roundingMode = softfloat_round_odd; float64_t sum = f64_add( prod, f64C );