Bug 687420 - /rangecheck in initgraphics with /Orientation != 0
Summary: /rangecheck in initgraphics with /Orientation != 0
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 8.14
Hardware: PC Linux
: P2 normal
Assignee: Jack Moffitt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-12 13:23 UTC by Daniel Glöckner
Modified: 2008-12-19 08:31 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
patch (1.05 KB, patch)
2004-05-09 08:09 UTC, Alex Cherepanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Glöckner 2004-04-12 13:23:11 UTC
My Ghostscript build has a problem rendering files with /Orientation != 0,
because make_adjustment_matrix uses gs_matrix_rotate which generates a matrix
containing two very very small numbers (2.65358e-17) != 0.0 .
This causes gs_setdotorientation to fail because both is_xxyy and is_xyyx are false.
It is generally a bad idea to test floating point numbers for equality.

Example:
<</Orientation 1>> setpagedevice
Comment 1 Alex Cherepanov 2004-05-08 04:43:58 UTC
Please provide a complete example.
I was unable to reproduce this problem by rinning "<</Orientation 1>>
setpagedevice" before the file.
Comment 2 Daniel Glöckner 2004-05-08 13:47:54 UTC
gs -c "<</Orientation 1>> setpagedevice"
is the full testcase.

The reason for the error is GCC (tested 2.95.3 and 3.4) doing the quot = ang /
90 in gs_sincos_degrees as a multiplication with the reciprocal of 90 when
compiling with -ffast-math.
Unfortunately the reciprocal can only inaccurately be represented, so that in
truth a division by 89.9999999999999965652475175.. is done.
The following floor(quot) == quot fails although the difference is marginal.
arad = ang * (M_PI / 180) is (with and without -ffast-math) compiles to a
multiplication with a constant that must be inaccurate.
Therefore sin and cos return numbers != 1.0 and 0.0.

Here again a test for equality between floating point numbers is not doing what
it was supposed to do.
Comment 3 Alex Cherepanov 2004-05-09 08:09:38 UTC
Created attachment 654 [details]
patch

Prevent GCC with -ffast-math from converting a/90. into a*(1/90.) .

I think this is the easiest solution. This code has been running fine
on a wide variety of compilers and systems for years. I don't see the
need to do radical changes now.
Comment 4 Alex Cherepanov 2004-05-11 13:50:36 UTC
The fix with improved comments is committed to the HEAD branch.