Board index FlightGear Development

Trouble with double types and textranslate

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Trouble with double types and textranslate

Postby godarklight » Sat Jun 01, 2013 9:25 am

This is more of an information post that will hopefully save someone about half an hours messing around. I didn't find any thread with this information (I did use the search function) so I'm posting it here to help someone out. Not sure if this is the correct place for it, but it's as good as anywhere...

The property tree / double data types doesn't understand fractions properly, To it 108.1 is really 108.0999999999999 (doubles don't hold all fractions properly). I was having problems animating a frequency selector, the work around to this can be found in c172p/Instruments/kx165/kx165-1.xml.

<bias>0.0001</bias>

And my concorde will now continue to progress slowly.

*EDIT: I wrote floats instead of doubles, but they suffer the same problem.
godarklight
 
Posts: 29
Joined: Sat Aug 18, 2012 9:31 am
Callsign: DARK-L
Version: 2.12
OS: Linux

Re: Trouble with double types and textranslate

Postby radi » Sun Jun 02, 2013 8:28 pm

Not sure what your actual problem was/is, but this
godarklight wrote in Sat Jun 01, 2013 9:25 am:To it 108.1 is really 108.0999999999999 (doubles don't hold all fractions properly).

is a general problem of any finite precision floating point number, not just the ones FG uses. Quoting wikipedia: "The use of the equality test (if (x==y) ...) requires care when dealing with floating point numbers. Even simple expressions like 0.6/0.2-3==0 will, on most computers, fail to be true."
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 643
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: Trouble with double types and textranslate

Postby godarklight » Mon Jun 03, 2013 2:56 pm

I understand the representation problem with floats (for example 0.1 cannot be represented, but 0.5 0.25 .. etc can), It was just messing up textranslate when using a step/factor value. I'll add a line into the wiki (if I can) to save someone a few headaches.
godarklight
 
Posts: 29
Joined: Sat Aug 18, 2012 9:31 am
Callsign: DARK-L
Version: 2.12
OS: Linux


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest