The simFlight Network Forums

# Issues with Offset 02B4

## Recommended Posts

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!

##### Share on other sites

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

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.