On Tue, 25 Apr 2006, Peter Onion wrote: > On Tue, 2006-04-25 at 09:22 -0700, jshayden wrote: >> Using the c18 libraries, does anyone have an example of using the math >> functions in math.h. I'm am getting trash output. I thought it returned >> IEEE floating point, but it doesn't appear to. Not even the sign bit is >> correct. Here is a basic example I've tried working with. >> >> #include >> #include >> >> void main(void) >> { >> >> float_t x = 3.14; >> float_t z; >> >> z = cos(x); >> >> } >> >> >> z's output is as follows... >> 00110110 11010110 11111011 00010110 >> ...which is nowhere close to -1. > > What do you expect to see for -1 ? In a floating point format I would > expect to see something representing -0.5 * 2^1 (2^1 being 2 raised to > the power 1). That's not the point. All the trig math functions expect radian input. E.g. try: float_t pi; pi = atan(1) * 4.0; z = cos( pi / 4.0 ); ... A suitable constant for pi is defined somewhere (in math,h) as M_PI afair. Peter -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist