[gdal-dev] Precission problem with atof
jorge.arevalo at gmail.com
Wed Jul 22 19:57:21 EDT 2009
2009/7/23 Mateusz Loskot <mateusz at loskot.net>:
> Jorge ArĂŠvalo wrote::
>> Context: GDAL WKT Raster Driver
>> While creating the Dataset, I execute this query:
>> SELECT srid, ST_AsText(extent), pixelsize_x, pixelsize_y, blocksize_x,
>> blocksize_y FROM raster_columns WHERE r_table_name = 'table' AND
>> r_column = 'rast'
>> I have loaded a 3-band tiff file with gdal2tiles. Its pixel size is
>> 0.9. If I execute this line (over the result of the previous query):
>> fPixelSizeX = atof(PQgetvalue(hPGresult, 0, 2));
>> I get 0.899999976158142 instead of 0.9.
>> The string obtained wiht PQgetvalue is "0.9", but, for any reason,
>> atof transform this string in 0.899999976158142.
>> So, seems to be a
>> precission problem. think the string used by atof has any problem, but
>> I'm not sure
> Most computers suffer of this problem.
>> What should I do?
> You need to learn how to live with that problem :-)
>> I tried to change atof(nptr) for strtod(nptr,
>> (char**)NULL), but it didn't work...
> And it won't help.
> Best regards,
> Mateusz Loskot
Yes, a stupid problem. I used float instead of double.
Actually, last year at university, I had a similar problem, but adding
really small numbers to a big one. I should remember this kind of
things. Normally, I remember them just after clicking on "Send"
I'm very sorry. And many thanks for the link!
More information about the gdal-dev