Shop OBEX P1 Docs P2 Docs Learn Events
float32full.atan help? — Parallax Forums

float32full.atan help?

JavalinJavalin Posts: 892
edited 2008-08-07 19:02 in Propeller 1
Hello all,

I am trying to use the floatlib library (float32full bits) to perform atans.

I don't get the answer back I expect compared with my calculator... Help?

This is what I am doing:
OBJ
    float32           : "Float32full"
    floatstring       : "floatstring"

 
pub start
    float32.start
 
    ' 5cm/3.9cm = 1.2820 = 52.04 degree's...!
    
    answer1 := float32.fdiv(5.0,3.9)
    answer2 := float32.atan(answer1)
 
    debug.str(string("a1 ="))    

    debug.str(floatstring.FloatToString(answer1))
    debug.putc(13)
    debug.str(string("a2 ="))    
    debug.str(floatstring.FloatToString(answer2))
    debug.putc(13)
    debug.putc(13)


As return values I get
a1 = 1.282051 (correct)
a2 = 0.9083684 (I am expecting 52.04... degree's)

(note := I have seen the post regarding the atan table error - and have the latest code form obex.parallax.com I believe..!)

Cheers!

James

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-07 18:46
    Usually trig functions deal with angles in radians, not degrees. 2 Pi radians = 360 degrees

    Try multiplying by 180 / Pi
  • JavalinJavalin Posts: 892
    edited 2008-08-07 19:02
    ah - thanks Mike.

    Suspected it might be my maths!
    For those interested - the fix is:
    CON
        rad2deg       = 57.29577
     
     
    PUB Start
        float32.start
        ' 5/3.9 = 1.2820 = 52.04 degree's...!
        
        answer1 := float32.fdiv(5.0,3.9)
        answer2 := float32.atan(answer1)
    
        answer3 := float32.fmul(answer2,rad2deg)               ' <-------------
     
        debug.str(string("a1 = "))    
        debug.str(floatstring.FloatToString(answer1))
        debug.putc(13)
        debug.str(string("a2 = "))    
        debug.str(floatstring.FloatToString(answer2))
        debug.putc(13)    
        debug.str(string("a3 = "))    
        debug.str(floatstring.FloatToString(answer3))    
        debug.putc(13)
        debug.putc(13)
     
    

    results are now:
    a1 = 1.282051
    a2 = 0.9083684
    a3 = 52.04567

    Cheers

    James





    Post Edited (Javalin) : 8/7/2008 7:09:23 PM GMT
Sign In or Register to comment.