e_scalb.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (C) 2011-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <math.h>
  16. #include <math_private.h>
  17. static double
  18. __attribute__ ((noinline))
  19. invalid_fn (double x, double fn)
  20. {
  21. if (rint (fn) != fn)
  22. return (fn - fn) / (fn - fn);
  23. else if (fn > 65000.0)
  24. return __scalbn (x, 65000);
  25. else
  26. return __scalbn (x,-65000);
  27. }
  28. double
  29. __ieee754_scalb (double x, double fn)
  30. {
  31. if (__glibc_unlikely (isnan (x)))
  32. return x * fn;
  33. if (__glibc_unlikely (!isfinite (fn)))
  34. {
  35. if (isnan (fn) || fn > 0.0)
  36. return x * fn;
  37. if (x == 0.0)
  38. return x;
  39. return x / -fn;
  40. }
  41. if (__glibc_unlikely (fabs (fn) >= 0x1p31 || (double) (int) fn != fn))
  42. return invalid_fn (x, fn);
  43. return __scalbn (x, (int) fn);
  44. }
  45. strong_alias (__ieee754_scalb, __scalb_finite)