Announcement

Collapse
No announcement yet.

SINe function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SINe function

    on page 61 of Diablo16 Internal function Manual , section 2.3.5 SIN(angle) is example:

    var myvar, angle;
    angle := 133;
    myvar := SIN(angle);
    This example returns 92 in variable myvar.


    OK, I assume, the variables myvar and angle are integers.
    That's a problem because sin (133) is 0.7341 and that is not an integer.
    Beside it, sin (133) is not 92 ....

    My question: purpose of this function ?
    Last edited by JPL; 3 weeks ago.

  • #2
    The same is on next page of the manual for COSine:

    var myvar, angle;
    angle := 133;
    myvar := COS(angle);
    This example returns -86 in variable myvar.


    Cos (133) is not -86 .... that's -0.682 and that is not integer ! If I try to use float variable, I get an error message.

    Any idea?

    Comment


    • #3
      Hi,

      As stated on the Diablo16 Internal Functions:

      "The returned value range is from 127 to -127 which is a more useful representation for graphics work. The real sine values vary from 1.0 to -1.0 so appropriate scaling must be done in user code as required."

      Since the result will be easier to plot on the display. Can I ask how do you want to process the data?

      Perhaps, you might want to use the flt_SIN(&result, &floatval). Please refer to Section 2.21 Floating Point Functions of the Manual.

      Best Regards,
      Kevin

      Comment


      • #4
        Hi Kevin,
        I wish you and your company successful year 2020.
        Yes, in my project I use the float sine function.
        Just, not only understand the Sine/Cos functions on pages 61/62 ...

        angle := 133;
        myvar := COS(angle);
        This example returns -86 in variable myvar.


        What is -86 in this example?
        Why range -127 to +127? Why not range -180 to +180 ?

        Comment


        • #5
          Hi,

          Thank you for your greetings and your kind words.
          The range of -127 to 127 comes from a signed byte representation (one's complement).
          The -86 is the value mapped on the given range.

          Best Regards,
          Kevin

          Comment


          • #6
            Kevin,
            I understand range <-127, +127>. That is < -2E7, +2E7 >. But I don't understand how you get expression

            -86 = cos (133 )

            Please, can you write me in mathematical form the function

            angle := 133;
            myvar := COS(angle);
            This example returns -86 in variable myvar.


            Thanks

            Jiri

            Comment


            • #7
              Hi Jiri,

              I think that there is some misunderstanding. The -86 is the return value of the given function ranging from 127 to -127. This is not the real value for the cosine function. The real value ranges from 1 to -1. If you desire the real cosine values, you need to map the return value so you can scale it accordingly.

              I hope this helps.

              Best Regards,
              Kevin

              Comment

              Working...
              X