Borland C++ 4.5, there's wrong with Incrementing using dcmal

  • Jan Jeremy Go
  • Newbie
  • Newbie
  • User avatar
  • Posts: 13
  • Loc: Philippines

Post 3+ Months Ago

I use Borland C++ 4.5, I just discovered, there's wrong with it or bug.

Simple example:
C Code: [ Select ]
#include<stdio.h>
#include<conio.h>
 
void main(void)
{
   int ctr, y = 0;
   float num2 = 0.000000;
 
   for(ctr = 1; ctr < 21; ctr++)
   {
      if((y >= 0) && (y <= 2))
      {
         gotoxy(4,22+y);
         if((num2 == 0.0) || (num2 == 0.5) || (num2 == 1.0))
            printf("Good! %f is accurate, there's no extra or less decimal number........", num2);
         else
            printf("Bad! %f isn't accurate, maybe there's extra or less decimal number...", num2);
         y++;
         if(y == 3)
         {
            gotoxy(51,22+y);
               printf(". .. ........like 0.00...01!");
         }
      }
      gotoxy(1,ctr);
         printf("%f\t", num2);
         num2 += 0.1;
      gotoxy(17,ctr);
         printf("%f\t", num2);
         num2 += 0.1;
      gotoxy(33,ctr);
         printf("%f\t", num2);
         num2 += 0.1;
      gotoxy(49,ctr);
         printf("%f\t", num2);
         num2 += 0.1;
      gotoxy(65,ctr);
         printf("%f\n", num2);
         num2 += 0.1; //Even if you try write 0.100000, it's useless 0.100000 == 0.1.
   }                  //Same in 0.01 or 0.001 and so on is still have common problem.
}
 
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. void main(void)
  5. {
  6.    int ctr, y = 0;
  7.    float num2 = 0.000000;
  8.  
  9.    for(ctr = 1; ctr < 21; ctr++)
  10.    {
  11.       if((y >= 0) && (y <= 2))
  12.       {
  13.          gotoxy(4,22+y);
  14.          if((num2 == 0.0) || (num2 == 0.5) || (num2 == 1.0))
  15.             printf("Good! %f is accurate, there's no extra or less decimal number........", num2);
  16.          else
  17.             printf("Bad! %f isn't accurate, maybe there's extra or less decimal number...", num2);
  18.          y++;
  19.          if(y == 3)
  20.          {
  21.             gotoxy(51,22+y);
  22.                printf(". .. ........like 0.00...01!");
  23.          }
  24.       }
  25.       gotoxy(1,ctr);
  26.          printf("%f\t", num2);
  27.          num2 += 0.1;
  28.       gotoxy(17,ctr);
  29.          printf("%f\t", num2);
  30.          num2 += 0.1;
  31.       gotoxy(33,ctr);
  32.          printf("%f\t", num2);
  33.          num2 += 0.1;
  34.       gotoxy(49,ctr);
  35.          printf("%f\t", num2);
  36.          num2 += 0.1;
  37.       gotoxy(65,ctr);
  38.          printf("%f\n", num2);
  39.          num2 += 0.1; //Even if you try write 0.100000, it's useless 0.100000 == 0.1.
  40.    }                  //Same in 0.01 or 0.001 and so on is still have common problem.
  41. }
  42.  

****************************************
**If you try to check the watch the result is this:**
_____________________________________________
****************************************
*****+Process Of+*****++Incrementing of 0.1++**
*****+++num++++*****++++++++++++++++++**
****************************************
..................0.0 - 0.7..................
.........0.8000001 - 0.9000001........
..................1.0 - 2.7..................
..........2.799999 - 3.799999..........
..........3.899998 - 5.099998..........
..........5.199997 - 6.099997..........
..........6.199996 - 7.199996..........
..........7.299995 - 8.299995..........
..........8.399996 - 8.499996..........
..........8.599997 - so on... ...........
..........and so far..... ...................
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Is there a reason your using Borland? The release date could very well be older than you are. If you can I'd suggest downloading the free version of Visual Studio Express.
  • Satwant
  • Graduate
  • Graduate
  • User avatar
  • Posts: 127
  • Loc: Bangalore

Post 3+ Months Ago

Jan Jeremy Go wrote:
I use Borland C++ 4.5, I just discovered, there's wrong with it or bug.


It is not a bug, its general Float Problem with C/c++ Compilers. To get Rid of this Try to set precision to absolute places to use number with comparison operator. Or The following function can help you :)

Code: [ Select ]

bool AreSame(double a, double b)
{
  return fabs(a - b) < EPSILON;
}
  1. bool AreSame(double a, double b)
  2. {
  3.   return fabs(a - b) < EPSILON;
  4. }
  • Satwant
  • Graduate
  • Graduate
  • User avatar
  • Posts: 127
  • Loc: Bangalore

Post 3+ Months Ago

SpooF wrote:
Is there a reason your using Borland? The release date could very well be older than you are. If you can I'd suggest downloading the free version of Visual Studio Express.


And Borland C++ is a Great Compiler. MS Visual C++ Compiler is Just a Window Only thing which keep u away from standard Portable world of C/C++ Party. While with practicing on Borland u can also easily write code for Unix, Linux and Mac Platforms. :)
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Borland C++ was last released in 1999, the version the post is using was released in 1994. The Borland C++ project no longer exists it has (after a few morphs) turned into C++ Builder, last release August 30, 2010.

There is no reason to use Borland C++.
  • Satwant
  • Graduate
  • Graduate
  • User avatar
  • Posts: 127
  • Loc: Bangalore

Post 3+ Months Ago

Hello SpooF
SpooF wrote:
Borland C++ was last released in 1999, the version the post is using was released in 1994. The Borland C++ project no longer exists it has (after a few morphs) turned into C++ Builder, last release August 30, 2010.

There is no reason to use Borland C++.


Application Developement is not simply depend on Any version of Compiler. When i start practicing 'c' it was very old borland compiler implemented in ouw university labs. as u mention
SpooF wrote:
the version the post is using was released in 1994

The thing is to understand concept related to Language so u can implement them on any platform at any level.

And one more Little instructing thing, in India Normally 90% of companies organized job tests for newbies based on this old borland compiler , and most newbies are forced to work with these compilers. :oops:
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6254
  • Loc: Seattle, WA

Post 3+ Months Ago

I have to second Spoof here; stay away from Borland. If cross-platform development is a requirement of your project, use GCC.

Satwant wrote:
Application Developement is not simply depend on Any version of Compiler.


Wrong. Compiler versions play a HUGE part in software development, especially on larger projects. Even minute differences in the minor build version of a compiler/linker can cause issues.
  • Satwant
  • Graduate
  • Graduate
  • User avatar
  • Posts: 127
  • Loc: Bangalore

Post 3+ Months Ago

Satwant wrote:
Application Development is not simply depend on Any version of Compiler.


spork wrote:
Wrong. Compiler versions play a HUGE part in software development, especially on larger projects. Even minute differences in the minor build version of a compiler/linker can cause issues.


The Sense of my Answer is Not about making of building Huge or Medium Application, This is about learning language features. The Microsoft Visual C++ have very different look and feel from slandered ASCII 'C' compilers, Designed to rapid application development only on window. So i always oppose MS c++ as first time learning Language. :)

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 54 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.