Quote:
|
Originally Posted by EricS-Team180
ummm...that's a new one me or maybe I'm just missing something obvious...
just what is an FX format? I typically think of x has hex and f as floating point???
Thanks,
Eric
|
I am not sure of the notation, but if I were writing the sin & cos routines, I would return 16 bit signed number that would be be 2^15 (a.k.a 32768) times the "true" value of the functions. For example, while -1<= Sin <= 1, I would have -32768 <= DrJoeSin <= 32768. Where DrJoeSin = 32768 * Sin
As to Tan this is trickier. My first thought would be to just to just use the definition of tan = sin/cos which would mean tan = DrJoeSin/DrJoeCos. In principle this is okay, but in integer math this is pretty aweful...
...Tan has another problem in that cos can equal zero (or tan can equal infinity). If we are going to return a 16 bit answer, infinity, in this case, is going to have to be 2^15 I suppose.
That still leaves us with a problem. If we are going to use the same basic trick of defining DrJoeTan = ScaleFactor * Tan.
The practical problem is that you don't know where the user of the tan function is going to want his/her function to be accurate. If ScaleFactor is 32768 as in sin and cos, then whenever tan is greater than 1 (that is, whenever abs(theta) > pi/4), DrJoeTan is going to return 32768 (a.k.a. infinity)... ...not exactly a very good result. But then again, in the range that it works (whenever abs(theta) < pi/4), it returns the most data you can expect from a 16 bit number.
Is this a case were we would like to have a modified floating point number format? Perhaps something where we return an exponent and a mantissa? Perhaps it would be even better to have a combined Tan/Sec function that returns a flag telling you if it is returning Sec or Tan and then it returns a 16 bit value for either Tan or Sec depending on which one is less than "infinity"? <-- a crazy idea, but it could be made to work I suppose.
I suppose that this is all a solved problem but I'll be dag nabbed if I have worked it all out already... ...and kickoff is less than a week away...
As another exercise for the user, I have been using radians as my argument for sin, cos, tan, etc. but of course this is non-sense in interger land. Should we define a 16 bit equivalent to PBasic's Brads (all funtions are defined from -32767 to 32768 where 32768 = pi and -32768 = -pi)?
Just more grist for the mill...
Joe J.
P.S. Do you think FIRST really thought all this through for us when the made the leap to C? I suppose not. This is going to be a tough year for folks to learn on. Buckle your seatbelts, it is going to be a bumpy ride...