fef8.c 570 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * $Source$
  3. * $State$
  4. * $Revision$
  5. */
  6. /* no headers allowed! */
  7. /* Given a double, calculates the mantissa and exponent.
  8. *
  9. * This function is intended to be called internally by the code generator,
  10. * so the calling convention is odd.
  11. */
  12. int __fef8(double* fp)
  13. {
  14. double f = *fp;
  15. int exponent, sign;
  16. if (f == 0.0)
  17. return 0;
  18. if (f < 0.0)
  19. {
  20. sign = -1;
  21. f = -f;
  22. }
  23. else
  24. sign = 0;
  25. exponent = 0;
  26. while (f >= 1.0)
  27. {
  28. f /= 2.0;
  29. exponent++;
  30. }
  31. while (f < 0.5)
  32. {
  33. f *= 2.0;
  34. exponent--;
  35. }
  36. *fp = (sign) ? -f : f;
  37. return exponent;
  38. }