If the result didn't fit into a PIC, you should be able to take the result, look for optimizations (at piclist.com) and tell the compiler to use them next time. Properly defining the size of the parameters to a function also helps to define the accuracy needed. Most C compilers will use EXACTLY the same code to generate a SQRT no matter if the incoming value is a char or a long. The routine library at piclist.com has SQRT routines ranging from 53 instructions and 19 cycles worst case for a char all the way up to 58 words 439 cycles worst for a 32bit long. I'll bet no C compiler even comes close to that. Why isn't there an easy way to teach a compiler to use the best code available from a large, open, massmind optimized library? --- James Newton (PICList Admin #3) mailto:jamesnewton@piclist.com 1-619-652-0593 PIC/PICList FAQ: http://www.piclist.com or .org -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Drew Vassallo Sent: Friday, March 02, 2001 05:56 To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: Switch / If Statement revisited >one question, how about > >double x = sqrt(ln(cos(2*PI*(double)AD_result)??? > >in asm? > >What I would say, the C compiler is in this case much faster and better, >just press the compile button. But would it even FIT in a PIC?? Try fitting a code snippet like that into a 12C508 or something similar. Sometimes, some of the more complex math routines can be rewritten/modified for the specific math calculation that needs to be done or specific problems with the application (or processor) that need to be addressed. For example, there are many 16x16bit multipliers out there, some of which use less RAM/more program memory, and vice versa. Depending on how much space/RAM you have to work with, one might be preferable over the other. Also, depending on the accuracy you need, you can make concessions with the cosine or PI approximations in your example. Granted, typing out what you want and pressing "compile" is much easier and faster than the hours and hours (+ skill) required to do this in assembly. Personally, I don't think I'd want to do complex math too often in asm. On the other hand, try doing precision PWM cycling, delay loops, or freqency timing in C. You'll be begging for assembly in those cases. --Andrew _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu