Announcement

Collapse
No announcement yet.

COS function

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

  • COS function

    PBP manual states that COS interprets the input value as radians, but apparently interprets it as degrees.

    for i=0 to 10
    real[i]=cos i
    next i

    Returns

    127....123

    There's more to the story, so I guess I just don't understand it. Cos(60) returns 12, which is neither degrees nor radians input if scaling a (-1 to 1) output range to a (-127 to +127) specified output range.

    Can someone explain how to get correctly scaled (-127 to 127, equivalent to -1 to 1) COS output for a raw radian input from the PBP COS function?
    Last edited by Chuck Curtis; 03-26-2019, 06:45 PM.

  • #2
    It looks like I have to multiply the raw radian input by 256/(2*pi), or ~40.74, then feed it to the COS function. Man, not exactly what I had in mind.
    Last edited by Chuck Curtis; 03-26-2019, 09:40 PM. Reason: 256 was 255(incorrect), ~40.74 was ~40.58(incorrect)

    Comment


    • #3
      google brad for some more info in binary scaling

      try this

      Code:
      result var byte
      i var byte
      c var byte
      v var byte
      sb var byte
      pause 3000
      
      debug 13,10,9,"angle",9,"Brad",9,"Cos",9,"Dec",13,10
      
      for i=0 to 180 step 10
      c =       i*256/360
      result = cos  c
      v=100*abs(result)/128
      if result.7 then
      sb="-"
      else
      sb=" "
      endif
      
      debug 9,#i,9,#c,9,sdec result,9,sb,"0.",sdec v,13,10
      next
      stop

      Code:
          angle    Brad    Cos    Dec
          0    0    127     0.99
          10    7    125     0.97
          20    14    120     0.93
          30    21    111     0.86
          40    28    98     0.76
          50    35    83     0.64
          60    42    65     0.50
          70    49    46     0.35
          80    56    25     0.19
          90    64    0     0.0
          100    71    -22    -0.17
          110    78    -43    -0.33
          120    85    -63    -0.49
          130    92    -81    -0.63
          140    99    -96    -0.75
          150    106    -109    -0.85
          160    113    -118    -0.92
          170    120    -125    -0.97
          180    128    -127    -0.99

      Comment


      • #4
        shame forums totally root up white space

        Click image for larger version

Name:	cos.jpg
Views:	27
Size:	77.1 KB
ID:	7646
        Last edited by richard; 03-26-2019, 09:16 PM.

        Comment


        • #5
          Thank you very much, Richard! I learned something that makes using the COS function (which I now know is based on brads) better than I originally thought. I am building lookup tables with entries composed of multiples of pi (which I had to round to integers, naturally), but since the function works on brads, pi gets divided out and I can work with integers directly and no rounding. Well, ya don't suppose that's the reason the COS function works that way, do ya?

          Comment

          Working...
          X