/**
 * safe math functions, avoids returning NaN
 * Warning: You should know what you are doing!
 */
/**
 * Returns the tangent of a number.
 * @param x A numeric expression that contains an angle measured in radians.
 * @returns always a number, no NaN
 */
export function tan(x) {
    if (x % Math.PI === (Math.PI / 2)) {
        console.warn("tan(x): undefined output! Using x = PI now.");
        x = 0;
    }
    return Math.tan(x);
}
/**
 * Returns the arcsine of a number.
 * @param x A numeric expression.
 * @returns always a number, no NaN
 */
export function asin(x) {
    if (x > 1.0) {
        console.warn("asin(x): x > 1", x);
        x = 1 /*- (x % Math.floor(x))*/;
    }
    else if (x < -1.0) {
        console.warn("asin(x): x < -1", x);
        x = -1 /*+ (1 - x % Math.floor(x))*/;
    }
    return Math.asin(x);
}
/**
 * Returns the arc cosine (or inverse cosine) of a number.
 * @param x A numeric expression.
 * @returns always a number, no NaN
 */
export function acos(x) {
    if (x > 1.0) {
        console.warn("acos(x): x > 1", x);
        x = 1 /*- (x % Math.floor(x))*/;
    }
    else if (x < -1.0) {
        console.warn("acos(x): x < -1", x);
        x = -1 /*+ (1 - x % Math.floor(x))*/;
    }
    return Math.acos(x);
}
/**
 * Returns the square root of a number.
 * @param x A numeric expression.
 * @returns always a number, no NaN
 */
export function sqrt(x) {
    if (x < 0) {
        console.warn("sqrt(x): x < 0", x);
        x = 0;
    }
    return Math.sqrt(x);
}
