Bug 687420

Summary: /rangecheck in initgraphics with /Orientation != 0
Product: Ghostscript Reporter: Daniel Glöckner <daniel-gl>
Component: GeneralAssignee: Jack Moffitt <jack>
Status: NOTIFIED FIXED    
Severity: normal    
Priority: P2    
Version: 8.14   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---
Attachments: patch

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.