summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/c
diff options
context:
space:
mode:
authorgdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>2000-11-30 23:44:32 +0000
committergdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>2000-11-30 23:44:32 +0000
commit42cd874bb39988ccee70de6702676e49ccdc1944 (patch)
tree02696b9245ae1ec0420e02fd6afbd46ad318c866 /libstdc++-v3/include/c
parentf0c9acadaba2c1daa20b9aaffdfc86e9d832c36f (diff)
downloadgcc-42cd874bb39988ccee70de6702676e49ccdc1944.tar.gz
* src/cmath.cc: Remove.
* src/Makefile.am (c_base_headers): Add bits/cmath.tcc. (sources): Remove cmath.cc * src/Makefile.in: Regenerate. * include/c/bits/std_cmath.h (__cmath_power<>): Declare. (__cmath_abs<>): New function. (abs, fabs): Use __cmath_abs when no direct support is available. (__pow_helper<>): New function. (pow): Define here. Use __pow_helper<>. * include/c/bits/cmath.tcc: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37901 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/c')
-rw-r--r--libstdc++-v3/include/c/bits/cmath.tcc53
-rw-r--r--libstdc++-v3/include/c/bits/std_cmath.h66
2 files changed, 98 insertions, 21 deletions
diff --git a/libstdc++-v3/include/c/bits/cmath.tcc b/libstdc++-v3/include/c/bits/cmath.tcc
new file mode 100644
index 00000000000..c61df979bfa
--- /dev/null
+++ b/libstdc++-v3/include/c/bits/cmath.tcc
@@ -0,0 +1,53 @@
+// -*- C++ -*- C math library.
+
+// Copyright (C) 2000 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This 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 General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// This file was written by Gabriel Dos Reis <gdr@codesourcery.com>
+
+#ifndef _CPP_BITS_CMATH_TCC
+#define _CPP_BITS_CMATH_TCC 1
+
+namespace std {
+ export template<typename _Tp>
+ _Tp
+ __cmath_power(_Tp __x, unsigned int __n)
+ {
+ _Tp __y = __n % 2 ? __x : 1;
+
+ while (__n >>= 1)
+ {
+ __x = __x * __x;
+ if (__n % 2)
+ __y = __y * __x;
+ }
+
+ return __y;
+ }
+}
+
+#endif
diff --git a/libstdc++-v3/include/c/bits/std_cmath.h b/libstdc++-v3/include/c/bits/std_cmath.h
index 307f618adec..30999c5f28d 100644
--- a/libstdc++-v3/include/c/bits/std_cmath.h
+++ b/libstdc++-v3/include/c/bits/std_cmath.h
@@ -44,6 +44,17 @@
namespace std
{
+ // Forward declaration of a helper function. This really should be
+ // an `exported' forward declaration.
+ template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);
+
+ template<typename _Tp>
+ inline _Tp
+ __cmath_abs(_Tp __x)
+ {
+ return __x < _Tp() ? -__x : __x;
+ }
+
inline long
abs(long __i) { return ::labs(__i); }
@@ -58,7 +69,7 @@ namespace std
abs(float __x) { return ::fabsf(__x); }
#else
inline float
- abs(float __x) { return ::fabs(static_cast<double>(__x)); }
+ abs(float __x) { return __cmath_abs(__x); }
#endif
#if _GLIBCPP_HAVE_ACOSF
@@ -137,7 +148,7 @@ namespace std
fabs(float __x) { return ::fabsf(__x); }
#else
inline float
- fabs(float __x) { return ::fabs(static_cast<double>(__x)); }
+ fabs(float __x) { return __cmath_abs(__x); }
#endif
#if _GLIBCPP_HAVE_FLOORF
@@ -204,6 +215,15 @@ namespace std
}
#endif
+ template<typename _Tp>
+ inline _Tp
+ __pow_helper(_Tp __x, int __n)
+ {
+ return __n < 0
+ ? _Tp(1)/__cmath_power(__x, -__n)
+ : __cmath_power(__x, __n);
+ }
+
#if _GLIBCPP_HAVE_POWF
inline float
pow(float __x, float __y) { return ::powf(__x, __y); }
@@ -213,8 +233,11 @@ namespace std
{ return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
#endif
- float
- pow(float, int);
+ inline float
+ pow(float __x, int __n)
+ {
+ return __pow_helper(__x, __n);
+ }
#if _GLIBCPP_HAVE___BUILTIN_SINF
inline float
@@ -315,8 +338,11 @@ namespace std
extern "C" double pow(double __x, double __y);
- double
- pow(double __x, int __i);
+ inline double
+ pow(double __x, int __i)
+ {
+ return __pow_helper(__x, __i);
+ }
#if _GLIBCPP_HAVE___BUILTIN_SIN
inline double
@@ -347,7 +373,7 @@ namespace std
abs(long double __x) { return ::fabsl(__x); }
#else
inline long double
- abs(long double __x) { return fabs(static_cast<double>(__x)); }
+ abs(long double __x) { return __cmath_abs(__x); }
#endif
#if _GLIBCPP_HAVE_ACOSL
@@ -426,7 +452,7 @@ namespace std
fabs(long double __x) { return ::fabsl(__x); }
#else
inline long double
- fabs(long double __x) { return ::fabs(static_cast<double>(__x)); }
+ fabs(long double __x) { return __cmath_abs(__x); }
#endif
#if _GLIBCPP_HAVE_FLOORL
@@ -503,8 +529,11 @@ namespace std
{ return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
#endif
- long double
- pow(long double, int);
+ inline long double
+ pow(long double __x, int __n)
+ {
+ return __pow_helper(__x, __n);
+ }
#if _GLIBCPP_HAVE___BUILTIN_SINL
inline long double
@@ -551,18 +580,13 @@ namespace std
inline long double
tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
#endif
-} // std
-
-#endif
-
-
-
-
-
-
-
-
+} // std
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+# include <bits/cmath.tcc>
+#endif
+#endif