cmath.tcc revision 132720
1218585Sjkim// -*- C++ -*- C math library.
2218585Sjkim
3245582Sjkim// Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc.
4218585Sjkim//
5218585Sjkim// This file is part of the GNU ISO C++ Library.  This library is free
6218585Sjkim// software; you can redistribute it and/or modify it under the
7218585Sjkim// terms of the GNU General Public License as published by the
8306536Sjkim// Free Software Foundation; either version 2, or (at your option)
9218585Sjkim// any later version.
10218585Sjkim
11218585Sjkim// This library is distributed in the hope that it will be useful,
12218585Sjkim// but WITHOUT ANY WARRANTY; without even the implied warranty of
13218585Sjkim// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14218585Sjkim// GNU General Public License for more details.
15218585Sjkim
16218585Sjkim// You should have received a copy of the GNU General Public License along
17218585Sjkim// with this library; see the file COPYING.  If not, write to the Free
18218585Sjkim// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19218585Sjkim// USA.
20218585Sjkim
21218585Sjkim// As a special exception, you may use this file as part of a free software
22218585Sjkim// library without restriction.  Specifically, if other files instantiate
23218585Sjkim// templates or use macros or inline functions from this file, or you compile
24218585Sjkim// this file and link it with other files to produce an executable, this
25218585Sjkim// file does not by itself cause the resulting executable to be covered by
26218585Sjkim// the GNU General Public License.  This exception does not however
27218585Sjkim// invalidate any other reasons why the executable file might be covered by
28218585Sjkim// the GNU General Public License.
29218585Sjkim
30218585Sjkim// This file was written by Gabriel Dos Reis <gdr@codesourcery.com>
31218585Sjkim
32218585Sjkim#ifndef _GLIBCXX_CMATH_TCC
33218585Sjkim#define _GLIBCXX_CMATH_TCC 1
34218585Sjkim
35218585Sjkimnamespace std
36218585Sjkim{
37218585Sjkim  template<typename _Tp>
38218585Sjkim    inline _Tp
39218585Sjkim    __cmath_power(_Tp __x, unsigned int __n)
40218585Sjkim    {
41218585Sjkim      _Tp __y = __n % 2 ? __x : 1;
42218585Sjkim
43218585Sjkim      while (__n >>= 1)
44218590Sjkim        {
45218585Sjkim          __x = __x * __x;
46218590Sjkim          if (__n % 2)
47218590Sjkim            __y = __y * __x;
48218585Sjkim        }
49218585Sjkim
50218585Sjkim      return __y;
51218585Sjkim    }
52218585Sjkim}
53218585Sjkim
54306536Sjkim#endif
55306536Sjkim