[postgis-devel] [wktraster] Core tests failure for r5841

Mateusz Loskot mateusz at loskot.net
Fri Jan 14 04:49:23 PST 2011


On 14/01/11 00:27, Mateusz Loskot wrote:
> Pierre,
> Sorry, I forgot.
> I think there is no need to trunc()

To follow with details, C cast is as valid as trunc() and will discard 
decimal part truncating number towards Zero as long as both numbers
fit same size in memory, like here:

float f32;
int i32 = (int)f32;

double f64;
int64_t i64 = (int64_t)f64;

But this is undefined conversion as float does not fit 16-bits:

float f32;
int16_t i16 = (int16_t)f32;

However, the C99 trunc() function provides some useful diagnostics
and copes with discontinuity like
trunc(NAN) == NAN or trunc(INFINITY) == INFINITY
whereas casting those to int yields garbage.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org



More information about the postgis-devel mailing list