scalbf.c 867 B

12345678910111213141516171819202122232425262728293031
  1. /* origin: FreeBSD /usr/src/lib/msun/src/e_scalbf.c */
  2. /*
  3. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
  4. */
  5. /*
  6. * ====================================================
  7. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  8. *
  9. * Developed at SunPro, a Sun Microsystems, Inc. business.
  10. * Permission to use, copy, modify, and distribute this
  11. * software is freely granted, provided that this notice
  12. * is preserved.
  13. * ====================================================
  14. */
  15. #include <math.h>
  16. float scalbf(float x, float fn)
  17. {
  18. if (isnan(x) || isnan(fn)) return x*fn;
  19. if (!isfinite(fn)) {
  20. if (fn > 0.0f)
  21. return x*fn;
  22. else
  23. return x/(-fn);
  24. }
  25. if (rintf(fn) != fn) return (fn-fn)/(fn-fn);
  26. if ( fn > 65000.0f) return scalbnf(x, 65000);
  27. if (-fn > 65000.0f) return scalbnf(x,-65000);
  28. return scalbnf(x,(int)fn);
  29. }