gallivm: Use nextafterf(0.5, 0.0) as rounding constant
authorMatt Turner <mattst88@gmail.com>
Wed, 21 Nov 2018 20:13:19 +0000 (12:13 -0800)
committerMatt Turner <mattst88@gmail.com>
Wed, 28 Nov 2018 19:22:47 +0000 (11:22 -0800)
commit2d48d5116bfe589804e60bbb8fcb261b7b208949
treeb5781c23006fc4db63cc59f9c60d65aff104feaa
parente2ad94d92884d084f726f22c6beca69a36c4569d
gallivm: Use nextafterf(0.5, 0.0) as rounding constant

The common truncf(x + 0.5) fails for the floating-point value just less
than 0.5 (nextafterf(0.5, 0.0)). nextafterf(0.5, 0.0) + 0.5, after
rounding is 1.0, thus truncf does not produce the desired value.

The solution is to add nextafterf(0.5, 0.0) instead of 0.5 before
truncating. This works for all values.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_arit.c