Pierre,<br>Sorry, I forgot.<br>I think there is no need to trunc()<br><br>-- <br>Mateusz Ĺoskot, <a href="http://mateusz.loskot.net">http://mateusz.loskot.net</a><br>(Sent from my mobile)<br><br>----- Reply message -----<br>From: "Pierre Racine" <Pierre.Racine@sbf.ulaval.ca><br>Date: Thu, Jan 13, 2011 23:56<br>Subject: [postgis-devel] [wktraster] Core tests failure for r5841<br>To: "Mateusz Loskot" <mateusz@loskot.net><br>Cc: "PostGIS Development Discussion" <postgis-devel@postgis.refractions.net>, "strk" <strk@keybit.net><br><br><br>Ok. good. Nobody answered the question about if we need to trunc before clamping...<br><br>>-----Original Message-----<br>>From: Mateusz Loskot [mailto:mateusz@loskot.net]<br>>Sent: 13 janvier 2011 18:54<br>>To: Pierre Racine<br>>Cc: PostGIS Development Discussion; strk<br>>Subject: Re: [postgis-devel] [wktraster] Core tests failure for r5841<br>><br>>On 13/01/11 18:49, Pierre Racine wrote:<br>>>> This is one of number of places where the problem exists.<br>>>> Others are rt_band_set_pixel, rt_band_set_nodata, and generally<br>>>> in any place where double is implicitly or explicitly squeezed in<br>>>> integral types.<br>>><br>>> I agree the solution should be apply for rt_band_set_pixel and rt_band_set_nodata.<br>>><br>>> Does everybody is happy with my code snippet implementing MIN/MAX?<br>><br>>Pierre,<br>><br>>The idea is good. Though, I would suggest to follow Sandro's suggestion<br>>to wrap it with reusable macros / functions. Spreading such branching<br>>and spreading in number of places yet injected in switch case statement<br>>will make the code an epic poetry, unnecessarily.<br>><br>>Following <stdint.h> type names we operate in the code, we could have<br>><br>>clamp_int16<br>>clamp_uint16<br>>clamp_int32<br>>clamp_uint32<br>>...<br>><br>>If we are happy to use C99/POSIX, then we can simplify the branching<br>><br>>int16_t clamp_int16(double value)<br>>{<br>>    return (int16_t)fmin(fmax((value), SHRT_MIN), SHRT_MAX);<br>>}<br>><br>>uint16_t clamp_uint16(double value)<br>>{<br>>    return (uint16_t)fmin(fmax((value), USHRT_MIN), USHRT_MAX);<br>>}<br>><br>>Then, in code the intentions are explicit and clear:<br>><br>>        case PT_16BSI:<br>>            {<br>>                int16_t *ptr = mem;<br>><br>>                for (i = 0; i < numval; i++)<br>>                    ptr[i] = clamp_int16_t(initialvalue);<br>>                checkvalint = ptr[0];<br>>                break;<br>>            }<br>><br>><br>>Best regards,<br>>--<br>>Mateusz Loskot, <a href="http://mateusz.loskot.net">http://mateusz.loskot.net</a><br>>Charter Member of OSGeo, <a href="http://osgeo.org">http://osgeo.org</a><br>>Member of ACCU, <a href="http://accu.org">http://accu.org</a><br><br><br>