Blame sysdeps/m68k/m680x0/fpu/e_pow.c

Packit 6c4009
/* Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include "mathimpl.h"
Packit 6c4009
Packit 6c4009
#ifndef SUFF
Packit 6c4009
#define SUFF
Packit 6c4009
#endif
Packit 6c4009
#ifndef float_type
Packit 6c4009
#define float_type double
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#define CONCATX(a,b) __CONCAT(a,b)
Packit 6c4009
#define s(name) CONCATX(name,SUFF)
Packit 6c4009
#define m81(func) __m81_u(s(func))
Packit 6c4009
Packit 6c4009
float_type
Packit 6c4009
s(__ieee754_pow) (float_type x, float_type y)
Packit 6c4009
{
Packit 6c4009
  float_type z;
Packit 6c4009
  float_type ax;
Packit 6c4009
  unsigned long x_cond, y_cond;
Packit 6c4009
Packit 6c4009
  y_cond = __m81_test (y);
Packit 6c4009
  if (y_cond & __M81_COND_ZERO)
Packit 6c4009
    return 1.0;
Packit 6c4009
  if (y_cond & __M81_COND_NAN)
Packit 6c4009
    return x == 1.0 ? x : x + y;
Packit 6c4009
Packit 6c4009
  x_cond = __m81_test (x);
Packit 6c4009
  if (x_cond & __M81_COND_NAN)
Packit 6c4009
    return x + y;
Packit 6c4009
Packit 6c4009
  if (y_cond & __M81_COND_INF)
Packit 6c4009
    {
Packit 6c4009
      ax = s(fabs) (x);
Packit 6c4009
      if (ax == 1.0)
Packit 6c4009
	return ax;
Packit 6c4009
      if (ax > 1.0)
Packit 6c4009
	return y_cond & __M81_COND_NEG ? 0 : y;
Packit 6c4009
      else
Packit 6c4009
	return y_cond & __M81_COND_NEG ? -y : 0;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (s(fabs) (y) == 1.0)
Packit 6c4009
    return y_cond & __M81_COND_NEG ? 1 / x : x;
Packit 6c4009
Packit 6c4009
  if (y == 2)
Packit 6c4009
    return x * x;
Packit 6c4009
  if (y == 0.5 && !(x_cond & __M81_COND_NEG))
Packit 6c4009
    return m81(sqrt) (x);
Packit 6c4009
Packit 6c4009
  if (x == 10.0)
Packit 6c4009
    {
Packit 6c4009
      __asm ("ftentox%.x %1, %0" : "=f" (z) : "f" (y));
Packit 6c4009
      return z;
Packit 6c4009
    }
Packit 6c4009
  if (x == 2.0)
Packit 6c4009
    {
Packit 6c4009
      __asm ("ftwotox%.x %1, %0" : "=f" (z) : "f" (y));
Packit 6c4009
      return z;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  ax = s(fabs) (x);
Packit 6c4009
  if (x_cond & (__M81_COND_INF | __M81_COND_ZERO) || ax == 1.0)
Packit 6c4009
    {
Packit 6c4009
      z = ax;
Packit 6c4009
      if (y_cond & __M81_COND_NEG)
Packit 6c4009
	z = 1 / z;
Packit 6c4009
      if (x_cond & __M81_COND_NEG)
Packit 6c4009
	{
Packit 6c4009
	  if (y != m81(__rint) (y))
Packit 6c4009
	    {
Packit 6c4009
	      if (x == -1)
Packit 6c4009
		z = (z - z) / (z - z);
Packit 6c4009
	    }
Packit 6c4009
	  else
Packit 6c4009
	    goto maybe_negate;
Packit 6c4009
	}
Packit 6c4009
      return z;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (x_cond & __M81_COND_NEG)
Packit 6c4009
    {
Packit 6c4009
      if (y == m81(__rint) (y))
Packit 6c4009
	{
Packit 6c4009
	  z = m81(__ieee754_exp) (y * m81(__ieee754_log) (-x));
Packit 6c4009
	maybe_negate:
Packit 6c4009
	  /* We always use the long double format, since y is already in
Packit 6c4009
	     this format and rounding won't change the result.  */
Packit 6c4009
	  {
Packit 6c4009
	    int32_t exponent;
Packit 6c4009
	    uint32_t i0, i1;
Packit 6c4009
	    GET_LDOUBLE_WORDS (exponent, i0, i1, y);
Packit 6c4009
	    exponent = (exponent & 0x7fff) - 0x3fff;
Packit 6c4009
	    if (exponent <= 31
Packit 6c4009
		? i0 & (1 << (31 - exponent))
Packit 6c4009
		: (exponent <= 63
Packit 6c4009
		   && i1 & (1 << (63 - exponent))))
Packit 6c4009
	      z = -z;
Packit 6c4009
	  }
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	z = (y - y) / (y - y);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    z = m81(__ieee754_exp) (y * m81(__ieee754_log) (x));
Packit 6c4009
  return z;
Packit 6c4009
}
Packit 6c4009
strong_alias (s(__ieee754_pow), CONCATX (s(__pow), _finite))