A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

MinGW Standard Library Differences

870 views · started by Isonyx ·
#1
MinGW Standard Library Differences
I was debugging some code in C++ with a friend when I ran into something interesting.

I was set up on Netbeans using MinGW's GCC compiler version 4.6.2, and my friend was using DevC++ which uses MinGW's GCC version 3.4.2.

At the time I was using the setprecision function included in the iomanip standard library file.

setprecision allows you to set decimal precision in output operations.

It was a simple operation that had a small error, I was setting the precision to 2 on 118.125 which should have given me 118.13.

Instead my output was 118.12. I checked the same code on my friend's computer and noticed that his functioned fine, outputting 118.13.

It was only a minor error in the way set precision normally worked, but I assumed the problem was with the compiler version.

I could have it wrong, but I believe each implementation of a compiler, can carry minor differences in the way they implement the standard library. Although this isn't a huge issue, it could have led to larger issues with larger calculations, even if it's only off a decimal.

Like I said, I could be wrong about why this is happening, so if anyone else has an explanation I'd be interested in knowing about it.

Have you guys run into any weird inconsistencies among different common compilers for a language?
#2
That's pretty strange, I've never seen anything like that before. Is there a parameter to choose whether you want to round up or down?
#3
Stapled wrote:
That's pretty strange, I've never seen anything like that before. Is there a parameter to choose whether you want to round up or down?

Nope, setprecision only takes one parameter.

Interesting update on it though. According to a few people who have run into the same problem, the issue is that computer's can't represent floating points perfectly.

Apparently if you have a number like 5.555 the computer actually stores it as something like 5.55499999999876, which rounds down to 5.55. So adding 0.000000001 to the decimal value gives me the number I'm looking for and seems to fix the rounding problems.
#4
>I was set up on Netbeans using MinGW's GCC compiler version 4.6.2, and my friend was using DevC++ which uses MinGW's GCC version 3.4.2.

This appears to be your problem. Look at the disparity there - you're using a 4.6.x build of the recent GCC compiler w/ NetBeans (another fairly recent IDE) while your "friend" or whatever is using the heavily deprecated DevC++ IDE and an outdated GCC 3.4.x.

Just get on the same page. DevC++ sucks. He/she should be using the same or another modern C++ IDE for debugging code. Use the same compiler version because you always want to do that anyway when collaborating with others unless there's some ulterior reason for doing so otherwise.
#5
>I was set up on Netbeans using MinGW's GCC compiler version 4.6.2, and my friend was using DevC++ which uses MinGW's GCC version 3.4.2.

This appears to be your problem. Look at the disparity there - you're using a 4.6.x build of the recent GCC compiler w/ NetBeans (another fairly recent IDE) while your "friend" or whatever is using the heavily deprecated DevC++ IDE and an outdated GCC 3.4.x.

Just get on the same page. DevC++ sucks. He/she should be using the same or another modern C++ IDE for debugging code. Use the same compiler version because you always want to do that anyway when collaborating with others unless there's some ulterior reason for doing so otherwise.

Yeah, like I said there are issues with compiler differences.
The textbook for the programming class is a few years old and guides one through the installation of DevC++.
I prefer Visual Studio or Netbeans for C++ programming. What's your IDE of choice?
#6
Isonyx wrote:
Yeah, like I said there are issues with compiler differences.
The textbook for the programming class is a few years old and guides one through the installation of DevC++.
I prefer Visual Studio or Netbeans for C++ programming. What's your IDE of choice?


For C/C++ programming? CodeBlocks or Netbeans usually. Although I experiment with a lot of different IDEs.