Author Topic: bug in Code::Blocks 16.01  (Read 5731 times)

Offline gts_47

  • Single posting newcomer
  • *
  • Posts: 2
bug in Code::Blocks 16.01
« on: September 19, 2017, 11:37:43 pm »
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.

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: bug in Code::Blocks 16.01
« Reply #1 on: September 20, 2017, 12:20:17 am »
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.
« Last Edit: September 20, 2017, 12:22:27 am by sodev »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: bug in Code::Blocks 16.01
« Reply #2 on: September 20, 2017, 06:41:02 am »
BTW: including bits/stdc++.h is not looking like a good and portable idea:)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Krice

  • Almost regular
  • **
  • Posts: 150
Re: bug in Code::Blocks 16.01
« Reply #3 on: September 21, 2017, 11:54:13 pm »
So what you are seeing are rounding errors

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;

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?
« Last Edit: September 21, 2017, 11:56:07 pm by Krice »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: bug in Code::Blocks 16.01
« Reply #4 on: September 22, 2017, 12:19:17 am »
Oh, just noticed that without std:: it calls the C library version, makes sense. But why they give different result?
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  !!