• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX Absolute time precision?

Messages
240
Country
germany
Hello!

There were several post about timers in the past and now I actually feel the need to make one, too.
I already coded some HOBBS timer for my gauge, but during my optimizations I stumbled over this problem:


Code:
(A:SIM ON GROUND,bool) 0 ==
(E:Absolute time, seconds) 1 % 0 ==
and
	if{ (L:flight_time_total,seconds) ++ (>L:flight_time_total,seconds) }

I thought that this should increase my flight time whenever the remainder of (E:Absolute time) / 1 is 0, therefor every second.

But it doesn't react at all. Could it be that the remainder is never 0, because of some strange time step intervals?

Or am I using the wrong code anyway?

Thank you in advance,
Steven
 
EDITED
EDITED

Some thoughts:

Should it be P:ABSOLUTE TIME?

From the SDK:
Code:
[B]Operator Operation        Arguments Example  Result  [/B]
%          taking modulo  1         5.3 %    5

This seems to take only one argument and gives the integer part. (This is different from the C/C++ % operator which gives the modulus, which is what you want.)

Your expression seems to evaluate 1 % which allows equals 1 and then compares that with 0.

Try testing the absolute value of the difference between the time and its integer part

Code:
(E:Absolute time, seconds)  (E:Absolute time, seconds) % - abs < 0.0001
 
Last edited:
Hi, mgh!

Thank you for taking the time to respond!

P:ABSOLUTE TIME and E:ABSOLUTE TIME seems to be exactly the same and upper-/ lowercase doesn't matter neither.

Does ABSOLUTE TIME return an integer or a float? If the latter, the modulus is unlikely to be exactly zero.

Nice thought. But how can I convert it?
I'm pretty new to XML and so I only tried

(E:ABSOLUTE TIME,seconds) int 1 % 0 ==

which didn't work.:(

Of course, I could break up my condition threshold to something like

Code:
(E:Absolute time, seconds) 1 % 0.5 &lt;

but then I would need to limit the action to be only executed one time while the condition is true (it's true for HALF A SECOND!)

Code:
(E:Absolute time, seconds) 1 % 0.5 &lt;
	if{ 	(L:done1,bool) 0 ==
		if{ (L:flight_time_total,seconds) ++ (>L:flight_time_total,seconds) 1 (>L:done1,bool) } }
	els{ 0 (>L:done1,bool) }

I just wonder, if my very first approach would be somehow possible as it seems a bit more efficient.:confused:

Best regards,
Steven
 
We seem to be at cross-purposes, probably because I had second thoughts and edited my post - possibly after you'd read it.

Check my comments about what % does according to the SDK
 
Try this
Code:
(E:Local time,seconds) int (L:sec_prev,seconds) != 
if{ 
	(E:Local time,seconds) int (>L:sec_prev,seconds) 
	(L:flight_time_total,seconds) ++ (>L:flight_time_total,seconds) 
}
 
Last edited:
I thought that this should increase my flight time whenever the remainder of (E:Absolute time) / 1 is 0, therefor every second.
But it doesn't react at all. Could it be that the remainder is never 0, because of some strange time step intervals?

It is almost impossible that you can obtain 0 as a remainder of Absolute Time, because it is a calculated value of type FLOAT (double).

Instead, try to compare like this:

(E:Absolute time, seconds) 1 % 0.055 &lt;

and it should work fine.

Tom
 
taguilo;634026 [FONT="Courier New" said:
(E:Absolute time, seconds) 1 % 0.055 &lt;[/FONT]

Is the SDK wrong? According to it, % takes a single argument. If so 1 % will always equal 1 so the expression will always return the same value.
 
Thank you a lot for your effort, guys!!

I did a test run :D

@ Luka:

Your code looked pretty simple and effective and I was just about to transfer it to my gauge. But in the 10 minutes test it showed a delay of 1 second per minute, although it was written to the same gauge like the others.

@ Tom:

I remember having tested my original code with 0.01,..., 0.05 and 0.06. Now I see that your 0.055 works absolutely flawlessly :banghead:

Consequence:

My code from post #3 and the original with Tom's edit show the exact same result.
The latter one uses less code.

The winner (from a noob's point of view) is:

Code:
(E:Absolute time, seconds) 1 % 0.055 &lt;
	if{ (L:flight_time_total,seconds) ++ (>L:flight_time_total,seconds) }

Many thanks, once again: this community is amazing!

Steven
 
@ Tom:

I remember having tested my original code with 0.01,..., 0.05 and 0.06. Now I see that your 0.055 works absolutely flawlessly :banghead:

Of course. And the best think you could do, if you want to keep growing in programming knowledge, is try to figure out why is that works with 0.055 and not with other number (0.01, etc).

Also, as a (probably irrelevant) sidenote, there are 94.44 % (17/18) possibilities that you will have, from a fraction to almost a complete extra second in your LocalVar regarding to the sim's seconds calculation...Food for thought :)

Tom
 
Well, yes the SDK is wrong, or at best misleading...

I'd suggest the SDK simply is wrong. % takes 2 arguments not 1 and the example is wrong 5.3 % = 5 which is not the modula but the integer part.

the Wiki you linked to is correct.

The result of actually using % seems even more unexpected

+19 +6.7 % = +5.6
+19 -6.7 % = +5.6
-19 +6.7 % = -5.6
-19 -6.7 % = -5.6

also

+6.7 +1 % = +0.7
+6.7 -1 % = +0.7
-6.7 +1 % = -0.7
-6.7 -1 % = -0.7

So using 1 as the second argument always returns the signed fractional part.

In C/C++ x y % seems to be equivalent to:

Code:
(fabs(x)/x)*(fabs(x)-int(fabs(x)/fabs(y))*fabs(y))
 
the Wiki you linked to is correct.
...
In C/C++ x y % seems to be equivalent to:

Code:
(fabs(x)/x)*(fabs(x)-int(fabs(x)/fabs(y))*fabs(y))
I'm not terribly surprised, since I spent several days working on that Wiki article and testing my hypotheses to obtain experiential proof for them... <blows gently on nails and buffs them subtly on vest> :rotfl:

That would be an intereresting test to validate. It looks reasonable at least! :cool:
 
That would be an intereresting test to validate. It looks reasonable at least! :cool:

I used the ACES tool to check it's results and C++ to compare them with the expression. They matched!

Feel free to use this in your Wiki.
 
In C/C++ x y % seems to be equivalent to:

Code:
(fabs(x)/x)*(fabs(x)-int(fabs(x)/fabs(y))*fabs(y))

In C++ it can be also as simple as:

Code:
fmod(x,y)

#include <math.h>
double fmod( double x, double y)

Tom
 
Well, in C/C++ you still have the % operator as well.

I think what 'mgh' was stating was the actual math behind the function.
 
I used the ACES tool to check it's results and C++ to compare them with the expression. They matched!

Feel free to use this in your Wiki.

Excellent. I've added both your's and Tom's observations to the Wiki article.
 
I guess that's because of the compiler's exception handler.
I made a quick test in VC++ 2010 and there is no error at all, so I assume that 0 is being assigned to the variable I used.

Tom
 
It seems that NaN (not a number) does show when testing with cout >> at runtime, but I think quiet could mean it shows nothing, always speaking of MS C++ compilers. Maybe assigning a NaN to another var turns into assigning a 0 value and that is what is displayed? Could this be a Borland property only?
BTW in Excel with y=0 gives error #DIV#.

Tom
 
Back
Top