File size: 1,781 Bytes
0d7ff87
4c5b4cf
0d7ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c5b4cf
 
 
 
 
 
 
 
 
d29336a
 
 
 
 
 
 
4c5b4cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import math
import gradio as gr

def inverse_trig_functions(value: float, function_name: str) -> str:
    """
    Calculates inverse trigonometric functions (asin, acos, atan) in degrees.
    Args:
        value: The value to calculate the inverse trigonometric function for.
               For asin and acos, must be between -1 and 1.
        function_name: "asin", "acos", or "atan".
    Returns:
        A string representing the result in degrees, or an error message.
    """
    if not isinstance(value, (int, float)):
        return "Error: Input value must be a number."
    func_name = function_name.lower()
    result_rad = 0.0
    if func_name == "asin":
        if -1 <= value <= 1:
            result_rad = math.asin(value)
        else:
            return "Error: Input for asin must be between -1 and 1."
    elif func_name == "acos":
        if -1 <= value <= 1:
            result_rad = math.acos(value)
        else:
            return "Error: Input for acos must be between -1 and 1."
    elif func_name == "atan":
        result_rad = math.atan(value)
    else:
        return "Error: Invalid function name. Choose 'asin', 'acos', or 'atan'."
    return f"{math.degrees(result_rad):.4f} degrees"

inverse_trig_interface = gr.Interface(
    fn=inverse_trig_functions,
    inputs=[
        gr.Number(label="Value"),
        gr.Radio(["asin", "acos", "atan"], label="Inverse Function")
    ],
    outputs="text",
    title="Inverse Trigonometry Calculator",
    description="Calculate inverse trigonometric functions (asin, acos, atan) and get the result in degrees. For asin and acos, input must be between -1 and 1. Example: asin(0.5) = 30 degrees.",
    examples=[
        [0.5, "asin"],
        [0.5, "acos"],
        [1, "atan"],
        [-1, "asin"]
    ]
)