<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Floating point error in turbo c++' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Floating point error in turbo c++' posted on the 'C and C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 14:25:45 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 14:25:45 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/385140/floating-point-error-in-turbo-c++/</link>
      <description>I wrote this code for a school project,since i use vista and dos doesn't work properly on it ,i normally use the emulator DOSBOX.The problem is this program runs well on DOSBOX but not on the normal DOS platform. It gives an error&lt;pre class="sourcecode"&gt; Floating point error:domain Abnormal program termination&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Here's the  code,its on text file encryption.My school requires me to use the ancient "turbo c++ 3.0"&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include&amp;lt;string.h&amp;gt;
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;fstream.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
#include&amp;lt;math.h&amp;gt;

 int strtoken(char k[]) {
    int N = strlen(k);
    int sum = 0   ;

            for (int q=0;q&amp;lt;N;q++)
                sum+= (int) k[q] ;

    int tok = sum%255;

  return tok;
 }

int strtoken2(char k1[]) {

   int N1 = strlen(k1);
   int sum1 = 0,t=0;
        for (int q1=0;q1&amp;lt;N1;q1++)
        {
            t = (int) k1[q1];
            t=pow(2,t);
            sum1+= (t%255) ;
            }

  int tok = sum1%255;

  return tok;
}


 int main() {
     clrscr();
     int choice,num;
     char ifname[20],ofname[20],Key[20],ch;

start:
			  clrscr();
    cout&amp;lt;&amp;lt;"\n------------------------------------------------------------------------------\n";
	cout&amp;lt;&amp;lt;"Texcrypt 1.0.\n";
	cout&amp;lt;&amp;lt;"\n";
	cout&amp;lt;&amp;lt;"------------------------------------------------------------------------------\n\n";
	cout&amp;lt;&amp;lt;"\t\t\t*-------------------*\n"&amp;lt;&amp;lt;"\t\t\t| 1) Encrypt. |\n"&amp;lt;&amp;lt;"\t\t\t| 2) Decrypt. |\n"&amp;lt;&amp;lt;"\t\t\t| 3) Help.    |\n\t\t\t| 4) Exit.    |\n"&amp;lt;&amp;lt;"\t\t\t*-------------------*\n";
	cout&amp;lt;&amp;lt;"\nEnter your choice: ";

	cin&amp;gt;&amp;gt;choice;




if(choice==3) {
 clrscr();

cout&amp;lt;&amp;lt;" Instructions \n ------------- \n\n\n 1.Choose whether to encrypt or decrypt a file ";
cout&amp;lt;&amp;lt;"\n 2.Enter the input and output filenames (if the file is in same directory as texcrypt ,if not,then enter the full path of the file)";
cout&amp;lt;&amp;lt;"\n 3.Enter the key to encrypt/decrypt the file with(your file will be encrypted on the basis of the key entered).";
cout&amp;lt;&amp;lt;"\n 4.The output file will be your encrypted/decrypted file";
cout&amp;lt;&amp;lt;"\n\n\n\nPress any key to return ...... ";

getch();

goto start;






}






else if(choice==4)
	  return 0;
	      char text[3][20] = {"","encrypted","decrypted"};

	clrscr();
		cout&amp;lt;&amp;lt;"Enter input filename : ";
		gets(ifname);
		fflush(stdin);
		cout&amp;lt;&amp;lt;"\n";
		int i;

		ifstream infile("");
		ofstream outfile("");
		   infile.open(ifname);

		if(!infile) {          // if file is not found
		cout&amp;lt;&amp;lt;"Error:File not found";
		goto end;
		}

		cout&amp;lt;&amp;lt;"Enter output filename : ";gets(ofname);fflush(stdin);
		cout&amp;lt;&amp;lt;"\n";







		   outfile.open(ofname);


		       switch(choice) {

                        case 1:cout&amp;lt;&amp;lt;"Enter key: ";

                                for(i=0;;i++)
                                {


                                        Key[i]=getch();


				    if (Key[i] == '\r')
					break;
		       cout&amp;lt;&amp;lt;"*";
                                    }
                                Key[i] = '\0';

// I think the error is somewhere overhere
			    int token= strtoken(Key);
			    int token2= strtoken2(Key);

			  fflush(stdin);
			      cout&amp;lt;&amp;lt;"\n";

				     while (infile) {

				      while(infile){

					infile.get(ch);
					if(!infile){
					  cout&amp;lt;&amp;lt;"\nThe file was successfully encrypted.";
					  getch();
					  goto end;
					  }

					ch=char((ch+token-(token2))%255);

					outfile.put(ch);
					   }
					   }

			    break;


						  case 2:
				cout&amp;lt;&amp;lt;"Enter key: ";

				for(i=0;;i++){
				    Key[i]=getch();


				    if (Key[i] == '\r')
					break;
					cout&amp;lt;&amp;lt;"*";

						}
				Key[i] = '\0';
				cout&amp;lt;&amp;lt;"\n";
				     fflush(stdin);
                                     int dtoken=strtoken(Key);
                                     int dtoken2=strtoken2(Key);

                                     while(infile) {

                                     while(infile) {

                                          infile.get(ch);
                                          if(!infile)
                                          {
                                                cout&amp;lt;&amp;lt;"\nThe file was successfully decrypted.";
                                                getch();
                                                goto end;
                                                }
                                                ch=char(((ch)-dtoken+(dtoken2))%255);
                                                outfile.put(ch);

                                           }
                                           }
                                    break;
								 }
								//end switch
								end:
								 infile.close();
								 outfile.close();

								 cout&amp;lt;&amp;lt;"\n\n\nPress any key to return ......... "          ;

								 getch();
								 goto start;

								   return 0;
								   }
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/385140/floating-point-error-in-turbo-c++/</guid>
      <pubDate>Mon, 02 Feb 2009 09:29:06 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/385174/re-floating-point-error-in-turbo-c++/#385174</link>
      <description>&lt;span style="color: Blue;"&gt;I don't know what is causing the error, but I can give you some feedback on the code.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: Here's the  code,its on text file encryption.My school requires me &lt;br /&gt;
: to use the ancient "turbo c++ 3.0"&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Blue;"&gt;That is a poor school then. You should download a free, modern compiler and use it on the side, so that you get chance to learn real standard C++.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;: #include&amp;lt;string.h&amp;gt;
: #include&amp;lt;stdio.h&amp;gt;
: #include&amp;lt;fstream.h&amp;gt;
: #include&amp;lt;conio.h&amp;gt;
: #include&amp;lt;math.h&amp;gt;

&lt;span style="color: Blue;"&gt; These header declarations aren't valid in C++. This is non-standard code that only works in TC.&lt;/span&gt;


 
:             t=pow(2,t);

&lt;span style="color: Blue;"&gt;I suspect this is what makes the error appear, since you aren't using float numbers elsewhere in the code. As a work-around, you could code an integer version of that function, it is quite simple to do.

Here is one you can use:

(change uint32 to unsigned long and uint16 to unsigned int)

uint32 gpfunc_intpow (uint16 base, uint16 exp)
{
  uint32 sum;

  if(exp == 0)                                   /* special case: x times 0 */
  {
    sum = 1;
  }
  else
  {
    uint16 i;

    sum = base;

    for(i=1; i&amp;lt;exp; i++)
    {
      sum *= base;
    }
  }

  return sum;
}&lt;/span&gt;



: goto start;

&lt;span style="color: Blue;"&gt;You should avoid using goto, it is frowned upon by a majority of the programming world, and can be replaced with loops, that are easier to read.&lt;/span&gt;




: 		fflush(stdin);

&lt;span style="color: Blue;"&gt;This is not standard C nor standard C++ and will not work on standard compilers. You can only fflush stdout, never stdin.&lt;/span&gt;

&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/385174/re-floating-point-error-in-turbo-c++/#385174</guid>
      <pubDate>Tue, 03 Feb 2009 01:22:05 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/385465/re-floating-point-error-in-turbo-c++/#385465</link>
      <description>thanks,i made some tweaks to get that exponent loop working and thanks for your suggestions on fflush too&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/385465/re-floating-point-error-in-turbo-c++/#385465</guid>
      <pubDate>Mon, 09 Feb 2009 09:05:22 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/387196/re-floating-point-error-in-turbo-c++/#387196</link>
      <description>I'm getting the same problem too. Say, what sort of "modern compiler" would you recommend if I'm to give up using Turbo C++?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/387196/re-floating-point-error-in-turbo-c++/#387196</guid>
      <pubDate>Wed, 11 Mar 2009 21:04:05 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/387203/re-floating-point-error-in-turbo-c++/#387203</link>
      <description>Dev - C++&lt;br /&gt;
or&lt;br /&gt;
Visual C 07 (or higher)&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/387203/re-floating-point-error-in-turbo-c++/#387203</guid>
      <pubDate>Wed, 11 Mar 2009 23:22:33 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/387226/re-floating-point-error-in-turbo-c++/#387226</link>
      <description>: I'm getting the same problem too. Say, what sort of "modern &lt;br /&gt;
: compiler" would you recommend if I'm to give up using Turbo C++?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Free compilers:&lt;br /&gt;
Dev C++ (gcc) www.bloodshed.net/dev/devcpp&lt;br /&gt;
Microsoft Visual Studio Express&lt;br /&gt;
Borland Turbo C++ Builder 2006  www.turboexplorer.com&lt;br /&gt;
&lt;br /&gt;
Commerical compilers:&lt;br /&gt;
Embarcadero Builder 2009  (former Borland)&lt;br /&gt;
Microsoft Visual Studio 2008</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/387226/re-floating-point-error-in-turbo-c++/#387226</guid>
      <pubDate>Thu, 12 Mar 2009 03:44:03 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/395181/re-floating-point-error-in-turbo-c++/#395181</link>
      <description>#include&amp;lt;math.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
#define EPS 0.000001&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
float F(float x);&lt;br /&gt;
float x1,x2,x3,x4,f1,f2,f3,f4,h1,h2,d1,d2,a0,a1,a2,h;&lt;br /&gt;
clrscr();&lt;br /&gt;
printf("\nInput three initial points \n");&lt;br /&gt;
scanf("%f %f %f",&amp;amp;x1,&amp;amp;x2,&amp;amp;x3);&lt;br /&gt;
f1=F(x1);&lt;br /&gt;
f2=F(x2);&lt;br /&gt;
f3=F(x3);&lt;br /&gt;
begin:&lt;br /&gt;
h1=x1-x3;&lt;br /&gt;
h2=x2-x3;&lt;br /&gt;
d1=f1-f2;&lt;br /&gt;
d2=f2-f3;&lt;br /&gt;
a0=f3;&lt;br /&gt;
a1=(d2*h1*h1-d1*h2*h2)/(h1*h2*(h1-h2));&lt;br /&gt;
a2=(d1*h2-d2*h1)/(h*h2*(h1-h2));&lt;br /&gt;
if(a1&amp;gt;0.0)&lt;br /&gt;
h=(-2.0*a0)/(a1+sqrt(a1*a1-4*a2*a0));&lt;br /&gt;
else&lt;br /&gt;
h=(-2.0*a0)/(a1-sqrt(a1*a1-4*a2*a0));&lt;br /&gt;
x4=x3+h;&lt;br /&gt;
f4=F(x4);&lt;br /&gt;
if(f4&amp;lt;=EPS)&lt;br /&gt;
{&lt;br /&gt;
printf("\n\nRoot By Muller'S Method\n\n");&lt;br /&gt;
printf("Root=%f\n",x4);&lt;br /&gt;
printf("\n");&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
 x1=x2;&lt;br /&gt;
 x2=x3;&lt;br /&gt;
 x3=x4;&lt;br /&gt;
 f1=f2;&lt;br /&gt;
 f2=f3;&lt;br /&gt;
 f3=f4;&lt;br /&gt;
 goto begin;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
float F(float x)&lt;br /&gt;
{&lt;br /&gt;
float f;&lt;br /&gt;
f=(x*x*x)+(2*x*x)+(10*x)-20;&lt;br /&gt;
return (f);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
hey compiler is showing me the same error please help me out!!!!!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/395181/re-floating-point-error-in-turbo-c++/#395181</guid>
      <pubDate>Sun, 16 Aug 2009 01:28:26 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431465/re-floating-point-error-in-turbo-c++/#431465</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431465/re-floating-point-error-in-turbo-c++/#431465</guid>
      <pubDate>Mon, 04 Mar 2013 07:22:48 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431466/re-floating-point-error-in-turbo-c++/#431466</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431466/re-floating-point-error-in-turbo-c++/#431466</guid>
      <pubDate>Mon, 04 Mar 2013 07:24:38 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431467/re-floating-point-error-in-turbo-c++/#431467</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431467/re-floating-point-error-in-turbo-c++/#431467</guid>
      <pubDate>Mon, 04 Mar 2013 07:26:29 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431468/re-floating-point-error-in-turbo-c++/#431468</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431468/re-floating-point-error-in-turbo-c++/#431468</guid>
      <pubDate>Mon, 04 Mar 2013 07:39:36 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431469/re-floating-point-error-in-turbo-c++/#431469</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431469/re-floating-point-error-in-turbo-c++/#431469</guid>
      <pubDate>Mon, 04 Mar 2013 07:41:25 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431471/re-floating-point-error-in-turbo-c++/#431471</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431471/re-floating-point-error-in-turbo-c++/#431471</guid>
      <pubDate>Mon, 04 Mar 2013 07:43:25 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431472/re-floating-point-error-in-turbo-c++/#431472</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431472/re-floating-point-error-in-turbo-c++/#431472</guid>
      <pubDate>Mon, 04 Mar 2013 07:51:13 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431473/re-floating-point-error-in-turbo-c++/#431473</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431473/re-floating-point-error-in-turbo-c++/#431473</guid>
      <pubDate>Mon, 04 Mar 2013 07:53:07 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: Floating point error in turbo c++</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/385140/431474/re-floating-point-error-in-turbo-c++/#431474</link>
      <description>you need to protect t=pow(2,t) before calling it.  You also might want to cast t into a double not an int for instance&lt;br /&gt;
double tmp=(double)t;&lt;br /&gt;
if(fabs(tmp)&amp;gt;1000.0)&lt;br /&gt;
    return some_error_code;&lt;br /&gt;
tmp=pow(2.0,tmp);&lt;br /&gt;
if(fabs(tmp)&amp;lt;32000.0)&lt;br /&gt;
   t=(int)tmp;&lt;br /&gt;
else&lt;br /&gt;
   return some_other_type_of_error&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/385140/431474/re-floating-point-error-in-turbo-c++/#431474</guid>
      <pubDate>Mon, 04 Mar 2013 07:54:56 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>