/**
 * This function calculates the magnitude of a complex number.
 *
 * @param real The real part of the complex number.
 * @param imag The imaginary part of the complex number.
 * @return The magnitude of the complex number.
 * @throws IllegalArgumentException If either the real or imaginary part is not a number.
 *
 * Examples:
 * calculateMagnitude(3.0, 4.0) -> 5.0
 * calculateMagnitude(0.0, 2.0) -> 2.0
 */
fun calculateMagnitude(real: Double, imag: Double): Double {

    // Handle error if the real or imaginary part is not a number
    if (!real.isFinite() || !imag.isFinite()) {
        throw IllegalArgumentException("Real and imaginary parts must be numbers.")
    }

    // Calculate the magnitude using the Pythagorean theorem
    val magnitude = Math.sqrt(real * real + imag * imag)
    return magnitude
}
/**
 * This function calculates the magnitude of a complex number.
 *
 * @param real The real part of the complex number.
 * @param imag The imaginary part of the complex number.
 * @return The magnitude of the complex number.
 * @throws IllegalArgumentException If either the real or imaginary part is not a number.
 *
 * Examples:
 * calculateMagnitude(3.0, 4.0) -> 5.0
 * calculateMagnitude(0.0, 2.0) -> 2.0
 */
fun calculateMagnitude(real: Double, imag: Double): Double {
/**
 * This function calculates the magnitude of a complex number.
 *
 * @param real The real part of the complex number.
 * @param imag The imaginary part of the complex number.
 * @return The magnitude of the complex number.
 * @throws IllegalArgumentException If either the real or imaginary part is not a number.
 *
 * Examples:
 * calculateMagnitude(3.0, 4.0) -> 5.0
 * calculateMagnitude(0.0, 2.0) -> 2.0
 */
fun calculateMagnitude(real: Double, imag: Double): Double {

    // Handle error if the real or imaginary part is not a number
    if (!real.isFinite() || !imag.isFinite()) {
        throw IllegalArgumentException("Real and imaginary parts must be numbers.")
    }

    // Calculate the magnitude using the Pythagorean theorem
    val magnitude = Math.sqrt(real * real + imag * imag)
    return magnitude
}