relativeError function Null safety

double relativeError(
  1. dynamic calculated,
  2. dynamic correct
)

Returns relative error between calculated and correct. The type of calculated and correct must match and can be any vector, matrix, or quaternion.

Implementation

double relativeError(dynamic calculated, dynamic correct) {
  if (calculated is num && correct is num) {
    final diff = (calculated - correct).abs().toDouble();
    return diff / correct;
  }
  // ignore: return_of_invalid_type
  return calculated.relativeError(correct);
}