isPowerOf10 function

bool isPowerOf10(
  1. double n
)

Whether n is an exact power of ten.

Ports isPowerOf10 (utilities.ts:645-648). Returns false for 0 and for every negative, because log10 yields -Infinity or NaN there and NaN % 1 == 0 is false in both languages.

Implementation

bool isPowerOf10(double n) {
  final logged = d3.log10(handleFloatingPointPrecisionError(n));
  if (!logged.isFinite) {
    return false;
  }
  // 1 is the modulus at utilities.ts:647: a whole log10 means a whole decade.
  return logged % 1 == 0;
}