From 8a032c016dea9f7c61f987bedd513b46845a7935 Mon Sep 17 00:00:00 2001 From: Werner LEMBERG Date: Thu, 17 Mar 2005 08:29:15 +0000 Subject: [PATCH] Add workaround for broken hypot() on Interix. * src/libs/libgroff/hypot.c: New wrapper file for `hypot'. * src/libs/libgroff/Makefile.sub (OBJS): Add `hypot.o'. (CSRCS): Add `hypot.c'. * src/include/lib.h: Declare `groff_hypot'. * src/preproc/grn/hgraph.cpp: Don't declare `hypot'. Use `groff_hypot'. * src/preproc/pic/pic.h: Don't declare `hypot'. * src/preproc/pic/object.cpp (hypot): Use `groff_hypot'. --- ChangeLog | 18 ++++++++++++++++ doc/Makefile.in | 2 +- src/include/lib.h | 4 +++- src/libs/libgroff/Makefile.sub | 2 ++ src/libs/libgroff/hypot.c | 48 ++++++++++++++++++++++++++++++++++++++++++ src/preproc/grn/hgraph.cpp | 16 +++++--------- src/preproc/pic/object.cpp | 4 ++-- src/preproc/pic/pic.h | 8 +------ 8 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 src/libs/libgroff/hypot.c diff --git a/ChangeLog b/ChangeLog index 29ceb26a..353b2686 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2005-03-16 Werner LEMBERG + + Add workaround for broken hypot() on Interix. + + * src/libs/libgroff/hypot.c: New wrapper file for `hypot'. + + * src/libs/libgroff/Makefile.sub (OBJS): Add `hypot.o'. + (CSRCS): Add `hypot.c'. + + * src/include/lib.h: Declare `groff_hypot'. + + * src/preproc/grn/hgraph.cpp: Don't declare `hypot'. + Use `groff_hypot'. + + * src/preproc/pic/pic.h: Don't declare `hypot'. + + * src/preproc/pic/object.cpp (hypot): Use `groff_hypot'. + 2005-03-15 Gaius Mulley * src/devices/grohtml/post-html.cpp diff --git a/doc/Makefile.in b/doc/Makefile.in index ac328e0c..da3eb89b 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -1,4 +1,4 @@ -# Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. # Written by Werner Lemberg # # This file is part of groff. diff --git a/src/include/lib.h b/src/include/lib.h index fd7d6fec..7fc18ce6 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989-2000, 2001, 2002, 2003 Free Software Foundation, Inc. +/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2005 + Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -29,6 +30,7 @@ extern "C" { const char *i_to_a(int); const char *ui_to_a(unsigned int); const char *if_to_a(int, int); + double groff_hypot(double, double); } /* stdio.h on IRIX, OSF/1, emx, UWIN, and MinGW include getopt.h */ diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub index d6ea0c2e..fc55f086 100644 --- a/src/libs/libgroff/Makefile.sub +++ b/src/libs/libgroff/Makefile.sub @@ -17,6 +17,7 @@ OBJS=\ getopt1.$(OBJEXT) \ glyphuni.$(OBJEXT) \ htmlhint.$(OBJEXT) \ + hypot.$(OBJEXT) \ iftoa.$(OBJEXT) \ invalid.$(OBJEXT) \ itoa.$(OBJEXT) \ @@ -88,6 +89,7 @@ CSRCS=\ $(srcdir)/getcwd.c \ $(srcdir)/getopt.c \ $(srcdir)/getopt1.c \ + $(srcdir)/hypot.c \ $(srcdir)/iftoa.c \ $(srcdir)/itoa.c \ $(srcdir)/matherr.c \ diff --git a/src/libs/libgroff/hypot.c b/src/libs/libgroff/hypot.c new file mode 100644 index 00000000..f45ab2cf --- /dev/null +++ b/src/libs/libgroff/hypot.c @@ -0,0 +1,48 @@ +/* Copyright (C) 2005 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NEED_DECLARATION_HYPOT + double hypot(double, double); +#endif /* NEED_DECLARATION_HYPOT */ + +double groff_hypot(double x, double y) +{ + double result = hypot(x, y); + +#ifdef __INTERIX + /* hypot() on Interix is broken */ + if (isnan(result) && !isnan(x) && !isnan(y)) + return 0.0; +#endif + + return result; +} + +#ifdef __cplusplus +} +#endif diff --git a/src/preproc/grn/hgraph.cpp b/src/preproc/grn/hgraph.cpp index 88fc6bec..01208951 100644 --- a/src/preproc/grn/hgraph.cpp +++ b/src/preproc/grn/hgraph.cpp @@ -8,19 +8,13 @@ #include "gprint.h" -#ifdef NEED_DECLARATION_HYPOT -extern "C" { - double hypot(double, double); -} -#endif /* NEED_DECLARATION_HYPOT */ - #define MAXVECT 40 #define MAXPOINTS 200 #define LINELENGTH 1 #define PointsPerInterval 64 #define pi 3.14159265358979324 #define twopi (2.0 * pi) -#define len(a, b) hypot((double)(b.x-a.x), (double)(b.y-a.y)) +#define len(a, b) groff_hypot((double)(b.x-a.x), (double)(b.y-a.y)) extern int dotshifter; /* for the length of dotted curves */ @@ -600,7 +594,7 @@ HGArc(register int cx, length = 0; - resolution = (1.0 + hypot(xs, ys) / res) * PointsPerInterval; + resolution = (1.0 + groff_hypot(xs, ys) / res) * PointsPerInterval; /* mask = (1 << (int) log10(resolution + 1.0)) - 1; */ (void) frexp(resolution, &m); /* A bit more elegant than log10 */ for (mask = 1; mask < m; mask = mask << 1); @@ -671,13 +665,13 @@ picurve(register int *x, for (; npts--; x++, y++) { /* traverse the line segments */ xp = x[0] - x[1]; yp = y[0] - y[1]; - nseg = (int) hypot((double) xp, (double) yp); + nseg = (int) groff_hypot((double) xp, (double) yp); xp = x[1] - x[2]; yp = y[1] - y[2]; /* `nseg' is the number of line */ /* segments that will be drawn for */ /* each curve segment. */ - nseg = (int) ((double) (nseg + (int) hypot((double) xp, (double) yp)) / + nseg = (int) ((double) (nseg + (int) groff_hypot((double) xp, (double) yp)) / res * PointsPerInterval); for (i = 1; i < nseg; i++) { @@ -795,7 +789,7 @@ Paramaterize(int x[], dy = y[j + 1] - y[j]; /* Here was overflowing, so I changed it. */ /* u[i] += sqrt ((double) (dx * dx + dy * dy)); */ - u[i] += hypot((double) dx, (double) dy); + u[i] += groff_hypot((double) dx, (double) dy); } } for (i = 1; i < n; ++i) diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp index 1f70c45b..ad468461 100644 --- a/src/preproc/pic/object.cpp +++ b/src/preproc/pic/object.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004 +/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -202,7 +202,7 @@ double operator*(const position &a, const position &b) double hypot(const position &a) { - return hypot(a.x, a.y); + return groff_hypot(a.x, a.y); } struct arrow_head_type { diff --git a/src/preproc/pic/pic.h b/src/preproc/pic/pic.h index 166e4e75..5b2db055 100644 --- a/src/preproc/pic/pic.h +++ b/src/preproc/pic/pic.h @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -25,12 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include -#ifdef NEED_DECLARATION_HYPOT -extern "C" { - double hypot(double, double); -} -#endif /* NEED_DECLARATION_HYPOT */ - #ifdef NEED_DECLARATION_RAND #undef rand extern "C" { -- 2.11.4.GIT