How to correctly pass a float from C# to C++ (dll) -


i'm getting huge differences when pass float c# c++. i'm passing dynamic float wich changes on time. debugger this:

c++ lonvel    -0.036019072    float c#  lonvel    -0.029392920    float 

i did set msvc++2010 floating point model /fp:fast should standard in .net if i'm not mistaken, didn't help.

now can't give out code can show fraction of it.

from c# side looks this:

namespace example {     public class wheel     {                public bool loging = true;         #region members              public intptr nativewheelobject;          #endregion members          public wheel()         {                        this.nativewheelobject = sim.dll_wheel_add();             return;         }          #region wrapper methods          public void setvelocity(float lonroadvelocity,float latroadvelocity {               sim.dll_wheel_setvelocity(this.nativewheelobject, lonroadvelocity, latroadvelocity);         }         #endregion wrapper methods     }      internal class sim     {         #region pinvokes         [dllimport(pluginname, callingconvention=callingconvention.cdecl)]                 public static extern void dll_wheel_setvelocity(intptr wheel,                      float lonroadvelocity, float latroadvelocity);         #endregion pinvokes      }        } 

and in c++ side @ exportfunctions.cpp:

export_api void dll_wheel_setvelocity(carwheel* wheel, float lonroadvelocity,      float latroadvelocity) {         wheel->setvelocity(lonroadvelocity,latroadvelocity); } 

so sugestions on should in order 1:1 results or @ least 99% correct results.

i believe may describe issue, http://msdn.microsoft.com/en-us/library/c151dt3s.aspx

i recommend choosing data type if possible.

floats can change 1 program or within same application. here reading on subject: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

so can either implement "almostequal" approach, or choose data type.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -