cmath.tcc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // -*- C++ -*- C math library.
  2. // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
  3. // Free Software Foundation, Inc.
  4. //
  5. // This file is part of the GNU ISO C++ Library. This library is free
  6. // software; you can redistribute it and/or modify it under the
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // Under Section 7 of GPL version 3, you are granted additional
  15. // permissions described in the GCC Runtime Library Exception, version
  16. // 3.1, as published by the Free Software Foundation.
  17. // You should have received a copy of the GNU General Public License and
  18. // a copy of the GCC Runtime Library Exception along with this program;
  19. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. // <http://www.gnu.org/licenses/>.
  21. // This file was written by Gabriel Dos Reis <gdr@codesourcery.com>
  22. /** @file cmath.tcc
  23. * This is a Standard C++ Library file.
  24. */
  25. #ifndef _GLIBCXX_CMATH_TCC
  26. #define _GLIBCXX_CMATH_TCC 1
  27. _GLIBCXX_BEGIN_NAMESPACE(std)
  28. template<typename _Tp>
  29. inline _Tp
  30. __cmath_power(_Tp __x, unsigned int __n)
  31. {
  32. _Tp __y = __n % 2 ? __x : _Tp(1);
  33. while (__n >>= 1)
  34. {
  35. __x = __x * __x;
  36. if (__n % 2)
  37. __y = __y * __x;
  38. }
  39. return __y;
  40. }
  41. _GLIBCXX_END_NAMESPACE
  42. #endif