/**
 * Calculates the final mass of a star after an infinite amount of time, given the initial mass and mass loss rate.
 *
 * @param initialMass the initial mass of the star in solar masses
 * @param massLossRate the rate at which the star loses mass in solar masses per year
 * @return the final mass of the star after an infinite amount of time in solar masses
 *
 * Note:
 * The mass loss rate should be a positive value.
 */
fun calculateStellarMass(initialMass: Double, massLossRate: Double): Double {

    var currentMass = initialMass

    while (true) {
        // Subtract the mass loss rate from the initial mass at each iteration
        currentMass -= massLossRate

        // Check if the star has completely lost all its mass
        if (currentMass <= 0) {
            return 0.0
        }

        // Check if the mass loss rate is equal to or greater than the current mass,
        // which would result in an infinite loop
        if (massLossRate >= currentMass) {
            return Double.NaN
        }
    }
}
/**
 * Calculates the final mass of a star after an infinite amount of time, given the initial mass and mass loss rate.
 *
 * @param initialMass the initial mass of the star in solar masses
 * @param massLossRate the rate at which the star loses mass in solar masses per year
 * @return the final mass of the star after an infinite amount of time in solar masses
 *
 * Note:
 * The mass loss rate should be a positive value.
 */
fun calculateStellarMass(initialMass: Double, massLossRate: Double): Double {
/**
 * Calculates the final mass of a star after an infinite amount of time, given the initial mass and mass loss rate.
 *
 * @param initialMass the initial mass of the star in solar masses
 * @param massLossRate the rate at which the star loses mass in solar masses per year
 * @return the final mass of the star after an infinite amount of time in solar masses
 *
 * Note:
 * The mass loss rate should be a positive value.
 */
fun calculateStellarMass(initialMass: Double, massLossRate: Double): Double {

    var currentMass = initialMass

    while (true) {
        // Subtract the mass loss rate from the initial mass at each iteration
        currentMass -= massLossRate

        // Check if the star has completely lost all its mass
        if (currentMass <= 0) {
            return 0.0
        }

        // Check if the mass loss rate is equal to or greater than the current mass,
        // which would result in an infinite loop
        if (massLossRate >= currentMass) {
            return Double.NaN
        }
    }
}