Output double instead of int in postscript code

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Output double instead of int in postscript code

Post by broucaries »

we have a bug at debian using an high precision printf see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=632065

You output double instead of int for pages and bounding box field (at least on ps.c, but i have not checked ps3 and pdf)

Please also notice that if you use %i and cast to int, that you need to create positive length bounding box so use ceil and floor in order to enforce this.

Bastien
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Output double instead of int in postscript code

Post by magick »

We consistently use %.20g and cast any value to double for printf statements. We conveniently get integers when the value is integer, floats for non-integer values, and scientific notation when the values get larger. The primary benefit is that ImageMagick includes many 64-bit values and %.20g typically handles these gracefully under Linux, Mac, and Windows. That is, we don't need to conditionally compile different embedded formatting to support 64-bit values (one way under Linux, a different way under Windows). However, you are suggesting that the %.20g fails under Debian for a 64-bit integer value and instead produces a floating point value? Can you post the Pages line of the file produced with
  • convert rose: -colorspace Gray test.ps
It would be useful to see the floating point value it produces (We don't have a Debian system). If everything other Linux distributions (i.e. Fedora, Redhat, CentOS, FreeBSD) and Windows produces an integer here, could it be a bug in the Debian printf formatting algorithm? Here is the requisite code:

Code: Select all

           (void) FormatLocaleString(buffer,MaxTextExtent,"%%%%Pages: %.20g\n",
              image_info->adjoin != MagickFalse ? (double)
              GetImageListLength(image) : 1.0);
Sure we can change this one statement to use %i instead but we would need to make this sort of formatting change in about 100 places in ImageMagick. And as mentioned we would need to use different embedded printf formatting for Linux and Windows to support 64-bit integer values.
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: Output double instead of int in postscript code

Post by broucaries »

The user use a non compliant IEEE754 float. You could close your bug if you support imagemagick only on IEE754
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: Output double instead of int in postscript code

Post by broucaries »

BTW for compatibility over all OS see gnulib http://www.gnu.org/software/gnulib/manu ... rintf.html
It has some nice lgpl code and as a source library could be included in your source
Post Reply