User forums > General (but related to Code::Blocks)

bug in Code::Blocks 16.01

(1/1)

gts_47:
Sorry for last topic .It's my bad.
I uninstalled Code::Blocks EP version 1.1.1    and    installed Code::Blocks 16.01,
But still found the same bug.
Please take a look at attached screenshots.
also c++ supports using namespace std ,
It gives correct answer in Ubuntu ,
so if Code::Blocks gives wrong answer then that's a bug in Code::Blocks.
---->Problem occurs in <bits/stdc++.h> with using namespace std with pow(10,4) when I did not take input;
---->and with <iostream> and <math.h> with pow(10,4) when I take input and save pow(10,4) in a variable then print;
above problems does not occur when I directly print pow(10,4) and not saving it in another variable
-----------------------> ** Problem occur only with pow(10,4) when I save it in a variable then print it .It gives 9999.
PS : screenshot attached.

sodev:
There is no bug in CodeBlocks, the bug are you! Or at most the bug is in the compiler you use. CodeBlocks doesnt output anything, the program your compiler made does the output. All what CodeBlocks does is start the compiler and run the resulting program.

The explanation for your different results is simple if you would look at the definition of the std::pow function: it returns a double (or float, dont know the exact int promotion rules atm). If you insert the result directly into an ostream the double overload gets called, if you store it in an int the double gets casted into an int and the int overload gets called. So what you are seeing are rounding errors. If they are caused by the compiler, caused by the c runtime library, caused by the cpu you run the program on or simply caused by the fact how floating point errors occur are unknown since you havent given any information about your environment.

So please stop calling out bugs that are caused by your absence of knowledge.

oBFusCATed:
BTW: including bits/stdc++.h is not looking like a good and portable idea:)

Krice:

--- Quote from: sodev on September 20, 2017, 12:20:17 am ---So what you are seeing are rounding errors
--- End quote ---

Are they? I tried this myself and found out something strange.


--- Code: ---#include <iostream>
#include <cmath>

std::cout<<std::pow(10,4);

int p=std::pow(10,4);
std::cout<<p;

--- End code ---

This has the same result (int p version is 9999), but for whatever reason if you remove std:: from pow both are 10000. Oh, just noticed that without std:: it calls the C library version, makes sense. But why they give different result?

Jenna:

--- Quote from: Krice on September 21, 2017, 11:54:13 pm ---Oh, just noticed that without std:: it calls the C library version, makes sense. But why they give different result?

--- End quote ---
You should ask it the compiler developers.

Your question has absolutely nothing to do with Code::Blocks and is therefore violating our forum rules.

Topic locked  !!

Navigation

[0] Message Index

Go to full version