s_ldexp.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. #include "math.h"
  12. #include "math_private.h"
  13. #include <errno.h>
  14. /* TODO: POSIX says:
  15. *
  16. * "If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
  17. * then errno shall be set to [ERANGE]. If the integer expression
  18. * (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow
  19. * floating-point exception shall be raised."
  20. *
  21. * *And it says the same about scalbn*! Thus these two functions
  22. * are the same and can be just aliased.
  23. *
  24. * Currently, ldexp tries to be vaguely POSIX compliant while scalbn
  25. * does not (it does not set ERRNO).
  26. */
  27. double ldexp(double value, int exp)
  28. {
  29. if (!isfinite(value) || value == 0.0)
  30. return value;
  31. value = scalbn(value, exp);
  32. if (!isfinite(value) || value == 0.0)
  33. errno = ERANGE;
  34. return value;
  35. }
  36. libm_hidden_def(ldexp)