w_scalbf.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright (C) 2011-2016 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. #if defined(__UCLIBC_HAS_FENV__)
  18. #include <errno.h>
  19. static float
  20. __attribute__ ((noinline))
  21. sysv_scalbf (float x, float fn)
  22. {
  23. float z = (float) __ieee754_scalb ((double) x, (double) fn);
  24. if (__builtin_expect (isinf (z),0))
  25. {
  26. if (isfinite (x))
  27. return __kernel_standard_f (x, fn, 132); /* scalb overflow */
  28. else
  29. __set_errno (ERANGE);
  30. }
  31. else if (__builtin_expect (z == 0.0f, 0) && z != x)
  32. return __kernel_standard_f (x, fn, 133); /* scalb underflow */
  33. return z;
  34. }
  35. #endif
  36. /* Wrapper scalbf */
  37. float
  38. scalbf (float x, float fn)
  39. {
  40. #if defined(__UCLIBC_HAS_FENV__)
  41. if (__builtin_expect (_LIB_VERSION == _SVID_, 0))
  42. return sysv_scalbf (x, fn);
  43. else
  44. {
  45. float z = (float) __ieee754_scalb ((double) x, (double) fn);
  46. if (__builtin_expect (!isfinite (z) || z == 0.0f, 0))
  47. {
  48. if (isnan (z))
  49. {
  50. if (!isnan (x) && !isnan (fn))
  51. __set_errno (EDOM);
  52. }
  53. else if (isinf (z))
  54. {
  55. if (!isinf (x) && !isinf (fn))
  56. __set_errno (ERANGE);
  57. }
  58. else
  59. {
  60. /* z == 0. */
  61. if (x != 0.0f && !isinf (fn))
  62. __set_errno (ERANGE);
  63. }
  64. }
  65. return z;
  66. }
  67. #else
  68. return (float) __ieee754_scalb ((double) x, (double) fn);
  69. #endif /* __UCLIBC_HAS_FENV__ */
  70. }