diff options
author | Matthew McClure <mcclurem@vmware.com> | 2013-09-26 16:57:26 -0700 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2013-10-04 10:55:51 +0100 |
commit | d164d50a85e5c42a8ed0c5082564f69e13aa09e0 (patch) | |
tree | eebc183fcb4e80ca2e45c4d18a61d2a758cbe784 /src/gallium/auxiliary/util/u_math.h | |
parent | b280516e114776c8d34c2d6fe0174762f3c85c0e (diff) | |
download | external_mesa3d-d164d50a85e5c42a8ed0c5082564f69e13aa09e0.zip external_mesa3d-d164d50a85e5c42a8ed0c5082564f69e13aa09e0.tar.gz external_mesa3d-d164d50a85e5c42a8ed0c5082564f69e13aa09e0.tar.bz2 |
util: when packing depth values, round to nearest.
This patch adds the lrint, lrintf, llrint, and llrintf rounding utility
functions. When packing unorm depth values, we will round to nearest.
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/util/u_math.h')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 702d4e9..478a4aa 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -162,7 +162,59 @@ float log2f(float f) #endif +#if __STDC_VERSION__ < 199901L && !defined(__cplusplus) +static INLINE long int +lrint(double d) +{ + long int rounded = (long int)(d + 0.5); + + if (d - floor(d) == 0.5) { + if (rounded % 2 != 0) + rounded += (d > 0) ? -1 : 1; + } + + return rounded; +} + +static INLINE long int +lrintf(float f) +{ + long int rounded = (long int)(f + 0.5f); + + if (f - floorf(f) == 0.5f) { + if (rounded % 2 != 0) + rounded += (f > 0) ? -1 : 1; + } + + return rounded; +} +static INLINE long long int +llrint(double d) +{ + long long int rounded = (long long int)(d + 0.5); + + if (d - floor(d) == 0.5) { + if (rounded % 2 != 0) + rounded += (d > 0) ? -1 : 1; + } + + return rounded; +} + +static INLINE long long int +llrintf(float f) +{ + long long int rounded = (long long int)(f + 0.5f); + + if (f - floorf(f) == 0.5f) { + if (rounded % 2 != 0) + rounded += (f > 0) ? -1 : 1; + } + + return rounded; +} +#endif /* C99 */ #define POW2_TABLE_SIZE_LOG2 9 #define POW2_TABLE_SIZE (1 << POW2_TABLE_SIZE_LOG2) |