Announcement

Collapse
No announcement yet.

Newbie questions

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

  • #21
    My solution to ATAN2, in the 80, when I was using a TRS-80 Model III
    For extended-precision values, make the necessary changes.
    Code:
    120 R1=57.29578!
        '
        ' SE contains delta sin
        ' SN contains delta cos
        ' ATAN2 returns in X
        '
    1910 IF SN=0 THEN X=90-(SE<0)*90 ELSE X=ATN(SE/SN)*R1-(SN<0)*180:IF X<0 THEN X=X+360
    
    Test code:
    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    
        LOCAL R1, SE, SN, X AS SINGLE
    
    120 R1=57.29578!
    1200 SE= 0:SN= 0:GOSUB 1910: PRINT "For SE= 0:SN= 0: ATAN2 should be   0" X 'prints 0
    1210 SE= 0:SN= 1:GOSUB 1910: PRINT "For SE= 0:SN= 1: ATAN2 should be   0" X 'prints 0
    1220 SE= 1:SN= 1:GOSUB 1910: PRINT "For SE= 1:SN= 1: ATAN2 should be  45" X 'prints 45
    1230 SE= 1:SN= 0:GOSUB 1910: PRINT "For SE= 1:SN= 0: ATAN2 should be  90" X 'prints 90
    1240 SE= 1:SN=-1:GOSUB 1910: PRINT "For SE= 1:SN=-1: ATAN2 should be 135" X 'prints 135
    1250 SE= 0:SN=-1:GOSUB 1910: PRINT "For SE= 0:SN=-1: ATAN2 should be 180" X 'prints 180
    1260 SE=-1:SN=-1:GOSUB 1910: PRINT "For SE=-1:SN=-1: ATAN2 should be 225" X 'prints 225
    1270 SE=-1:SN= 0:GOSUB 1910: PRINT "For SE=-1:SN= 0: ATAN2 should be 270" X 'prints 270
    1280 SE=-1:SN= 1:GOSUB 1910: PRINT "For SE=-1:SN= 1: ATAN2 should be 315" X 'prints 315
    1290 SE= 0:SN= 1:GOSUB 1910: PRINT "For SE= 0:SN= 1: ATAN2 should be   0" X 'prints 0
         WAITKEY$
         EXIT FUNCTION
    1910 IF SN=0 THEN X=-(SE<>0)*(90-(SE<0)*180) ELSE X=ATN(SE/SN)*R1-(SN<0)*180:IF X<0 THEN X=X+360
    1920 RETURN
    
    END FUNCTION
    
    atan2 test.zip
    "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

    Comment


    • #22
      Strickley in answer to question -
      For extended-precision values, make the necessary changes.
      change - LOCAL R1, SE, SN, X AS SINGLE
      to - LOCAL R1, SE, SN, X AS EXTENDED
      plus change degrees to radians

      (no other checks made for run time errors or compile time errors)

      ((The ATN function in PB is natively extended.))
      Last edited by Dale Yarker; 16 Aug 2016, 10:08 AM.
      Dale

      Comment


      • #23
        Strickley in answer to question -
        Hello Dale,
        Now I'm confused ...I didn't do a question. I just put a code for calculating the ATAN2 function. The complete code is on line 1910. I also know that the PB ATN function returns its value in extended-precision and the ATAN2 function will use this precision only if it is in the interest of the programmer. Typically, implementations of the ATAN2 function takes some space, I'd say about 10 lines of code - This version fit in just one line! But yes, to run in extended precision are necessary the changes that you indicated.
        Anyway my thanks!
        Arthur.
        Code:
            LOCAL R1, SE, SN, X AS EXT  'single
        
        120 R1=5.72957795130823209e+01##    '57.29578!


        "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

        Comment

        Working...
        X