cknipe Posted January 1, 2006 Report Posted January 1, 2006 Hi, Pete, I think there's a small error in the documentation... 0578, Pitch control: FSInterrogate gives: 4,261,696,370 (-2.78874 Factored) Documentation says: Pitch * 360 / (65546 * 65536). Ok, now let's do some math. 4,261,696,370 * 360 = 1,534,210,696,440 65536 * 65536 = 4,294,967,296 1,534,210,696,440 / 4,294,967,296 = 357.21 <-- A rather steap pitch, don't ya think? :shock: However, subtracting 360 from the answer, gives me -2.79 (Yes, my HP Calc rounds it off). Should the formula in the documentation thus not read: Bank * 360/(65536*65536)-360 ? Just want to make sure I get this right :) -- Chris.
Pete Dowson Posted January 1, 2006 Report Posted January 1, 2006 Pete, I think there's a small error in the documentation... No. In this case you are interpreting the value incorrectly as unsigned when, of course, pitch and bank (and magvar) are signed. Most of these angular values are given in the same units -- such that the maximum possible precision can be accommodated in the space available. Documentation says: Pitch * 360 / (65546 * 65536). Ok, now let's do some math.4,261,696,370 * 360 = 1,534,210,696,440 65536 * 65536 = 4,294,967,296 1,534,210,696,440 / 4,294,967,296 = 357.21 <-- A rather steap pitch, don't ya think? :shock: It is -2.79. Draw a circle and plot its position. You'll see that. Pirch and Bank have to be signed as they can be up/down or left/right. Should the formula in the documentation thus not read:Bank * 360/(65536*65536)-360 ? No, because then a position pitch or bank would turn out to be a big negative number. Please used signed values where that is sensible, unsigned where that is sensible. Regards, Pete
cknipe Posted January 2, 2006 Author Report Posted January 2, 2006 I am using signed Ints Pete... :( Int32, 4 Bytes, 32-Bit, Signed Integer, and Long, 8 Bytes, 64-Bit, Signed Integer (Which I have to use for the calculation, otherwise VB gets Overflow errors). For interest sakes, http://www.startvbdotnet.com/language/datatypes.aspx Result is always the same... When pitch is 4 Degrees UP, I get 356. When it should in fact be, -4. The strange part, is that it works for Bank, as well as MagVar (virtually the same code, just different offsets and formulas where needed). It's *just* pitch that's doing this... VB does something strange to * 360 / ( 65536 * 65536 ). Before I do the calculation, my data from FSUIPC matches on the spot with the data that FSI2 gives. After the calculation, I sit with the wrong answer. I'm starting to hate VB more and more now... Thanks anyways Pete (as always)... Time to go learn Delphi perhaps. -- C
Pete Dowson Posted January 2, 2006 Report Posted January 2, 2006 I am using signed Ints Pete... :( But 4,261,696,370 is not a possible number in 32-bit signed format. It is FE045372 in hexadecimal. The top bit is set (2^31) which is the sign bit. The value is actually -33270926 in decimal. ((-33270926 / 65536) * 360) / 65536 = -2.7887368 according to my calculator. [My calculator has only 8 digits so to maintain accuracy I split the two divides as you see -- you could do the same to keep it all fitting into 32 bits. But it is best to convert to floating point in any case, keeps your fractions]. VB does something strange to * 360 / ( 65536 * 65536 ). Well, if it started with a -ve number it must finish with one, else the compiler is in error. Sounds like, if you don't have a bug, Microsoft does! Regards, Pete
Stoney3K Posted January 17, 2006 Report Posted January 17, 2006 I am using signed Ints Pete... :( VB does something strange to * 360 / ( 65536 * 65536 ). Well, if it started with a -ve number it must finish with one, else the compiler is in error. Sounds like, if you don't have a bug, Microsoft does! Regards, Pete Not really. If you put them up like that (in integer numbers) VB will treat the values as INTS (32-bit!) and calculating 63336 squared times 360 will cause a huge overflow. I use these formulas in floating point (adding a .0 after every number) which doesn't cause the compiler to overflow in the calculations. Worked for me in C# where it didn't work if I typed the code as integers.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now