[Patch/libstdc++]: libmath/stubs.c (hypot) - Don't divide by zero.
Danny Smith
danny_r_smith_2001@yahoo.co.nz
Tue May 20 20:58:00 GMT 2003
I saw this while browsing sources. I supspect that most ports have their own
hypot so this has not been noticed.
This allows the libstdc++ stub version of hypot(0.0, 0.0) to return correct value.
Danny
ChangeLog
2003-05-20 Danny Smith <dannysmith@users.sourceforge.net>
* libmath/stubs.c (hypot, hypotf, hypotl): Don't divide by
zero.
Update copyright year.
Index: stubs.c
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libmath/stubs.c,v
retrieving revision 1.10
diff -c -3 -p -r1.10 stubs.c
*** stubs.c 1 Jan 2002 19:50:16 -0000 1.10
--- stubs.c 20 May 2003 10:04:10 -0000
***************
*** 1,6 ****
/* Stub definitions for libmath subpart of libstdc++. */
! /* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU ISO C++ Library. This library is free
software; you can redistribute it and/or modify it under the
--- 1,6 ----
/* Stub definitions for libmath subpart of libstdc++. */
! /* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU ISO C++ Library. This library is free
software; you can redistribute it and/or modify it under the
*************** float
*** 108,113 ****
--- 108,115 ----
hypotf(float x, float y)
{
float s = fabsf(x) + fabsf(y);
+ if (s == 0.0F)
+ return s;
x /= s; y /= s;
return s * sqrtf(x * x + y * y);
}
*************** double
*** 118,123 ****
--- 120,127 ----
hypot(double x, double y)
{
double s = fabs(x) + fabs(y);
+ if (s == 0.0)
+ return s;
x /= s; y /= s;
return s * sqrt(x * x + y * y);
}
*************** long double
*** 128,133 ****
--- 132,139 ----
hypotl(long double x, long double y)
{
long double s = fabsl(x) + fabsl(y);
+ if (s == 0.0L)
+ return s;
x /= s; y /= s;
return s * sqrtl(x * x + y * y);
}
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.
More information about the Libstdc++
mailing list