User forums > General (but related to Code::Blocks)
Possible GCC Bug?
(1/1)
Szabadember:
Hi!
I found something really weird! I think it's a bug in mingw gcc 3.4.4 (The compiler that came with the old codeblocks RC2)
Here's an example:
--- Code: ---#include <iostream>
#include <math.h>
using namespace std;
int main(){
int i,a;
for(i=0;i<10;i++){
a = pow(10,i);
printf("%d\n",a);
}
return 0;
}
--- End code ---
Output will be:
1
10
99
1000
9999
100000
1000000
9999999
99999999
999999999
If i use
--- Code: ---a = (float)pow(10,i);
--- End code ---
instead of
--- Code: ---a = pow(10,i);
--- End code ---
, output will be as expected. (1,10,100,1000,10000,...)
If i use
--- Code: ---a = pow(10,2);
--- End code ---
output will be also as expected. The problem occurs only if i use a variable as an argument.
Can you confirm this?
What is the most recent stable version of MingW?
My other problem is that i don't know how to compile gcc or gdb (of course i want to do this with codeblocks :D)
Biplab:
--- Quote from: Szabadember on October 14, 2007, 04:26:26 pm ---Can you confirm this?
What is the most recent stable version of MingW?
My other problem is that i don't know how to compile gcc or gdb (of course i want to do this with codeblocks :D)
--- End quote ---
If you pass int to pow which expects the arguments in float, you can get such values. Pass correct parameter types to get correct results.
The last stable version is 3.4.5. Though you can download latest 4.2.1 technology preview release.
You can't build GCC or GDB with C::B. I mean it's practically not feasible.
Szabadember:
--- Code: ---#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a;
float i;
for(i=0;i<10;i++){
a = (int)pow(10.0,i);
printf("%d\n",a);
}
return 0;
}
--- End code ---
What about that code, why isn't that working? I used floats for both arguments and converted the return type (which is float i think) to int, output still the same. And why is it working if i typecast the return type to (float) although a is (int) .
MortenMacFly:
--- Quote from: Szabadember on October 14, 2007, 05:00:54 pm ---What about that code, why isn't that working?
--- End quote ---
Please, this is *not* a general programming forum. Your question has nothing to do with C::B. Please ask such question in a C / C++ forum and/or read a book how floats are organised in memory and how cast's work.
With regards, Morten.
thomas:
--- Quote from: Szabadember on October 14, 2007, 05:00:54 pm ---What about that code, why isn't that working?
--- End quote ---
It's working fine, btw. It works exactly like it should be.
--- Quote ---and/or read a book how floats are organised in memory and how cast's work
--- End quote ---
What Martin said.
Navigation
[0] Message Index
Go to full version