dp_fint.c 820 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* IEEE754 floating point arithmetic
  3. * double precision: common utilities
  4. */
  5. /*
  6. * MIPS floating point support
  7. * Copyright (C) 1994-2000 Algorithmics Ltd.
  8. */
  9. #include "ieee754dp.h"
  10. union ieee754dp ieee754dp_fint(int x)
  11. {
  12. u64 xm;
  13. int xe;
  14. int xs;
  15. ieee754_clearcx();
  16. if (x == 0)
  17. return ieee754dp_zero(0);
  18. if (x == 1 || x == -1)
  19. return ieee754dp_one(x < 0);
  20. if (x == 10 || x == -10)
  21. return ieee754dp_ten(x < 0);
  22. xs = (x < 0);
  23. if (xs) {
  24. if (x == (1 << 31))
  25. xm = ((unsigned) 1 << 31); /* max neg can't be safely negated */
  26. else
  27. xm = -x;
  28. } else {
  29. xm = x;
  30. }
  31. /* normalize - result can never be inexact or overflow */
  32. xe = DP_FBITS;
  33. while ((xm >> DP_FBITS) == 0) {
  34. xm <<= 1;
  35. xe--;
  36. }
  37. return builddp(xs, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
  38. }