e_ilogbl.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Software floating-point emulation.
  2. ilogbl(x, exp)
  3. Copyright (C) 1999-2017 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jakub Jelinek (jj@ultra.linux.cz).
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C 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 GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. /* ilogbl(long double x)
  18. * return the binary exponent of non-zero x
  19. * ilogbl(0) = 0x80000001
  20. * ilogbl(inf/NaN) = 0x7fffffff (no signal is raised)
  21. */
  22. #include "soft-fp.h"
  23. #include "quad.h"
  24. #include <math.h>
  25. int __ieee754_ilogbl (long double x)
  26. {
  27. FP_DECL_EX;
  28. FP_DECL_Q(X);
  29. /*
  30. FP_UNPACK_Q(X, x);
  31. switch (X_c)
  32. {
  33. case FP_CLS_ZERO:
  34. return FP_ILOGB0;
  35. case FP_CLS_NAN:
  36. case FP_CLS_INF:
  37. return FP_ILOGBNAN;
  38. default:
  39. return X_e;
  40. }
  41. */
  42. FP_UNPACK_RAW_Q(X, x);
  43. switch (X_e)
  44. {
  45. default:
  46. return X_e - _FP_EXPBIAS_Q;
  47. case 0:
  48. #if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q
  49. if (_FP_FRAC_ZEROP_4(X))
  50. return FP_ILOGB0;
  51. else
  52. {
  53. _FP_I_TYPE shift;
  54. _FP_FRAC_CLZ_4(shift, X);
  55. shift -= _FP_FRACXBITS_Q;
  56. return X_e - _FP_EXPBIAS_Q - 1 + shift;
  57. }
  58. #else
  59. if (_FP_FRAC_ZEROP_2(X))
  60. return FP_ILOGB0;
  61. else
  62. {
  63. _FP_I_TYPE shift;
  64. _FP_FRAC_CLZ_2(shift, X);
  65. shift -= _FP_FRACXBITS_Q;
  66. return X_e - _FP_EXPBIAS_Q - 1 + shift;
  67. }
  68. #endif
  69. case _FP_EXPBIAS_Q:
  70. return FP_ILOGBNAN;
  71. }
  72. }