dp_flong.c 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_flong(s64 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 == (1ULL << 63))
  25. xm = (1ULL << 63); /* max neg can't be safely negated */
  26. else
  27. xm = -x;
  28. } else {
  29. xm = x;
  30. }
  31. /* normalize */
  32. xe = DP_FBITS + 3;
  33. if (xm >> (DP_FBITS + 1 + 3)) {
  34. /* shunt out overflow bits */
  35. while (xm >> (DP_FBITS + 1 + 3)) {
  36. XDPSRSX1();
  37. }
  38. } else {
  39. /* normalize in grs extended double precision */
  40. while ((xm >> (DP_FBITS + 3)) == 0) {
  41. xm <<= 1;
  42. xe--;
  43. }
  44. }
  45. return ieee754dp_format(xs, xe, xm);
  46. }