]> git.mxchange.org Git - flightgear.git/commitdiff
#897: float vs double precision issues (frequency dialog not always working)
authorThorstenB <brehmt@gmail.com>
Wed, 10 Oct 2012 18:28:17 +0000 (20:28 +0200)
committerThorstenB <brehmt@gmail.com>
Wed, 10 Oct 2012 18:28:17 +0000 (20:28 +0200)
puObject only provides float, not double, which causes precision/rounding
issues with some numerical values (try "114.2").
Work around: obtain string value, and manually convert with proper double
precision.

src/GUI/FGPUIDialog.cxx

index 9b2bc232a47087d536cede2d0fc0e58b3aeb36c8..3555d5039044645bf5888d72891769c6d3caa165 100644 (file)
@@ -491,9 +491,17 @@ copy_from_pui (puObject *object, SGPropertyNode *node)
         node->setIntValue(object->getIntegerValue());
         break;
     case props::FLOAT:
-    case props::DOUBLE:
         node->setFloatValue(object->getFloatValue());
         break;
+    case props::DOUBLE:
+    {
+        // puObject only provides float, not double, which causes precision/rounding issues
+        // with some numerical values (try "114.2").
+        // Work around: obtain string value, and manually convert with proper double precision.
+        const char *s = object->getStringValue();
+        node->setDoubleValue(atof(s));
+        break;
+    }
     default:
         const char *s = object->getStringValue();
         if (s)