Difference in double precision...

  • Thread starter Thread starter Sanjeev Azad
  • Start date Start date
S

Sanjeev Azad

I'm porting my application from VC++ 6.0 to VS .Net
and experiencing a difference in the double precisions.

I have the following code in my application

double val = 16e-6;

When I debug it, the debugger shows the value of val as
"1.599999999999999e-5", not "1.6000000000000e-5",
which is what the debugger shows in VC++6.0.

I understand that "1.599999999999999e-5" is the value that
actually gets stored in the memory for this double. However,
it seems that the value "1.599999999999999e-5" when used in arithmatic
operations fianlly gives a result which is different form what I get in
VC++6.0
I am unable to understand the reasoning behind the difference in the
results
in the two compilers.

I am looking for a way to ensure that math operations over numbers in .NET
output
gives same values as in VC++6.0. Are there any settings that need to be done
to achieve
this?

Thanks,
Sanjeev
 
Sanjeev Azad said:
I'm porting my application from VC++ 6.0 to VS .Net
and experiencing a difference in the double precisions.

I have the following code in my application

double val = 16e-6;

When I debug it, the debugger shows the value of val as
"1.599999999999999e-5", not "1.6000000000000e-5",
which is what the debugger shows in VC++6.0.

I understand that "1.599999999999999e-5" is the value that
actually gets stored in the memory for this double. However,
it seems that the value "1.599999999999999e-5" when used in arithmatic
operations fianlly gives a result which is different form what I get in
VC++6.0
I am unable to understand the reasoning behind the difference in the
results
in the two compilers.

I am looking for a way to ensure that math operations over numbers in .NET
output
gives same values as in VC++6.0. Are there any settings that need to be done
to achieve
this?

Thanks,
Sanjeev

Hey Sanjeev,

I think this might be possible because MS uses a slightly different
standard for double precision number representation from VC6 ("MS double")
to C++.NET (Double complies with the IEC 60559:1989 (IEEE 754) standard for
binary floating-point arithmetic.)

If you figure out more detailed stuff, please let me know.

Sebastian Dau
 
I am looking for a way to ensure that math operations over numbers in .NET
output
gives same values as in VC++6.0. Are there any settings that need to be done
to achieve
this?

Try setting the /Op (Improve Float Consistency) setting.

Dave
 
Back
Top