Browse Source

Update consoleDictionary.h

This fixes a problem I ran into with modulus operator on negative numbers. Internally, a variable is stored as a signed float and an unsigned int. Unfortunately this is done using a conversion directly from a signed float to an unsigned int which gives different results depending on hardware. For whatever reason mine was saving a -1 (or 4294967295) as the int regardless of the actual value which was then accessed to do the modulus. This fixes the problem by converting the value first to a signed int and then to an unsigned int.
Peter Robinson 3 years ago
parent
commit
b9e6486b38
1 changed files with 1 additions and 1 deletions
  1. 1 1
      engine/source/console/consoleDictionary.h

+ 1 - 1
engine/source/console/consoleDictionary.h

@@ -116,7 +116,7 @@ public:
             if(type <= TypeInternalString)
             if(type <= TypeInternalString)
             {
             {
                 fval = val;
                 fval = val;
-                ival = static_cast<U32>(val);
+                ival = static_cast<U32>(static_cast<S32>(val));
                 if(sval != typeValueEmpty)
                 if(sval != typeValueEmpty)
                 {
                 {
                     dFree(sval);
                     dFree(sval);