Jump to content
The simFlight Network Forums

Recommended Posts

Posted

For the offset of 02B4, ground speed.

 

I'm trying to get the offset into INT value, and then convert it the following gs in INT value. Example below.

this.gs = (this.fs_gs.Value * (3600 / 65536 / 1852));

Now if I only used this... it returns a value of 2681613.

this.gs = this.fs_gs.Value;

Now going back to the first code, it returns 0. Any reasons why?

 

Thanks!

Posted

For the offset of 02B4, ground speed.

 

I'm trying to get the offset into INT value, and then convert it the following gs in INT value. Example below.

this.gs = (this.fs_gs.Value * (3600 / 65536 / 1852));

Now if I only used this... it returns a value of 2681613.

this.gs = this.fs_gs.Value;

Now going back to the first code, it returns 0. Any reasons why?

 

Because you appear to be using integer arithmetic, and in integer arithmetic, where all fractions have to be discarded, the value

 

(3600 / 65536 / 1852)

 

is zero. In fact even just (3600 / 65536) is zero.

 

I suggest you do all your arithmetic using floating point values, like this (in C):

 

this.gs = (this.fs_gs.Value * (3600.0 / 65536.0 / 1852.0));

 

or, if you really have to stick to integers only, at least do the multiplications before the divisions, and also make the rest look more sensible (after all, does "/ 65536 / 1852" mean "divide by 65536/1852" or does it mean "divide by 65536 and then divide by 1852"? The compiler might know, but it isn't clear in normal school arithmetic, is it?

 

this.gs = (this.fs_gs.Value * 3600) / (65536 * 1852);

 

Applying this to 2681613 you see you will get 79 (or roughly 79.539 is "this.gs" is a floating point variable, not an integer).

 

Pete

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.