[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C++ floating point denormal

Posted on 2011-05-13
3
Medium Priority
?
808 Views
Last Modified: 2012-05-11
I have a large project with numerous floating point operations which I am converting from Visual C++ 6 to Visual Studio 2010 c++.  I've hit a problem in the different way that VS2010 deals with underflow denormals.

Consider the following code:
        unsigned int cw = _controlfp(0, 0);//this returns  589855 in both VC6 and VS2010
      float abba=12.5;
      int myin=0;
      for (myin=0; myin<100; myin ++)
      {
            abba = abba/10.1;
      }

Both VS2010 and VC6 behave the same up until abba reaches the FLT_MIN lower bound for a float, around 1e-38.  After that point in VC6 abba goes to 1e-45, and then to 0.0000.  In VS2010, it goes to a garbage 8e-39#DEN value.

500 points to the person who can show me how to get the VC6 behavior back.

Notice the _controlfp(0,0) integer in both VS2010 and VC6 they are the same, 589855.
0
Comment
Question by:ChemstationsDeveloper
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 1500 total points
ID: 35755225
The precise result in case of a floating point underflow is implementation defined, so there is no standard way of forcing 0.0f

However, MSDN claims that Visual Studio 2010 would set it to 0.0f in your case :

        http://msdn.microsoft.com/en-us/library/dt15s77h.aspx

so I'm not sure how to interpret the result you get.
0
 
LVL 8

Expert Comment

by:JIEXA
ID: 35810839
Try to use _control87() (or even __control87_2()) instead of _controlfp().
0
 

Author Closing Comment

by:ChemstationsDeveloper
ID: 35915205
thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Introduction to Processes
Loops Section Overview

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question