javaLongToInt method

dynamic javaLongToInt(
  1. num number
)

Implementation

javaLongToInt(num number) {
  int count = 0;
  final javaMinIntAbs = javaMinInteger.abs();

  final isNegative = number < 0;

  number = number.abs();

  if (number == javaMinIntAbs) return -number;

  if (number > javaMinIntAbs) {
    while (number > javaMinIntAbs) {
      number -= javaMinIntAbs;
      count++;
    }
    if (count % 2 == 1) {
      number -= javaMinIntAbs;
    }
  }
  return isNegative ? -number : number;
}