```ts
/**
 * a divided by b. Throws Error when divisor is zero (including -0) or not a finite number,
 * and returns NaN if both arguments are not numbers.
 */
export function safeDivide(a: number, b: number): number {
  if (isNaN(a) || isNaN(b)) {
    throw new Error('Both arguments must be finite numbers.');
  }
  if (b === 0) {
    throw new Error('Divisor cannot be zero.');
  }
  return a / b;
}
```