fractionPart static method

double fractionPart(
  1. double f
)

Implementation

static double fractionPart(double f) {
  if (f < 1) {
    if (f < 0) {
      return -fractionPart(-f);
    }
    return f;
  }

  final int e = exponent(f);
  double x = f;

  // Keep the top 12+e bits, the integer part; clear the rest.
  if (e < 64 - 12) {
    int hw0 = 0;
    int hw1 = 0;

    if (e <= 20) {
      hw0 = 0;
      hw1 = 1 << (64 - 12 - e - 32) - 1;
    } else {
      hw0 = 1 << (64 - 12 - e) - 1;
      hw1 = 0xFFFF;
    }

    x = mask(x, hw1, hw0);
  }
  return f - x;
}