```typescript
/**
 * Divides `a` by `b`, throwing an error if `b` is zero or if either argument is non-finite.
 */
export function safeDivide(a: number, b: number): number {
  if (isNaN(b) || !isFinite(b)) {
    throw new Error('Cannot divide by NaN or infinity');
  }
  if (a === Infinity && b < 0) {
    throw new Error('Cannot divide positive infinity by negative number');
  }
  if (b === -0 && a !== 0) {
    throw new Error('Cannot divide by zero');
  }
  return a / b;
}
```