sorry for my layman terminology, but to my understanding as a coder a function has a name, parameters, arguments and operations. if sin is the name, and its parameters are side opposite and hypotenuse, and its arguments are context dependent, what is the operation itself? am i making sense?

def sin (hypotenuse, opposite):
     ??!?!?!!?
  • Haus@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    I didn’t get what you were asking until I started to answer. The parameter is the angle. The algorithm is https://en.wikipedia.org/wiki/CORDIC . In (most?) compiled languages, this algorithm is performed on hardware. In (some?) interpreted languages, it’s done in hardware.

      • OwenEverbinde@lemmy.myserv.one
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        10 months ago

        An algorithm is the meat of a function. It’s the “how.”

        And if you’re using someone else’s function, you won’t touch the “how” because you’ll be interacting with the “what.” (You use a function for what it does.)

        You will be creating your own algorithm by writing code, however. Because an algorithm is just a sequence of steps that, taken together, constitute an attempt at achieving an objective.

        Haus is saying all the little steps that go into approximating sine occur directly on the hardware.

  • dmention7@lemm.ee
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    10 months ago

    This is kind of a weirdly phrased question.

    Mathematically, THE argument of the sine function is the angle in question. One definition of sine, using the sides of a right triangle, is the ratio of the opposite leg to the hypotenuse of said triangle: sin(theta)=opposite/hypotenuse.

    Edit: it occurred to me that maybe what you’re asking is how to compute the angle, theta, for which sin(theta) = a certain ratio of opposite/hypotenuse. There is an inverse sine function (often called arcsin) that does just that. Arcsin(opp/hyp)=theta. That’s the case where it would make sense to take the side lengths as arguments.

    • criitz@reddthat.com
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      10 months ago

      One way to think about it -

      The argument to the function is an angle

      The operation is:

      Draw a triangle with hypotenuse length 1, one angle 90, another angle is the one passed to the function

      Divide the length of the side opposite the passed angle by the length of the hypotenuse

      Return this value

      The other trig functions are the same with different sides being divided.