top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

GCC option for printing large number (large double)

+1 vote

I have an issue in printing a large number in a c program. Please find below the code snippet :

int main()
 double temp = 0.0;
 temp = pow(2, 2000);
 printf("The value of temp is %lfn", temp);
 return 0;

I compiled and ran as below:

$ gcc test.c -o test
$ ./test
The value of temp is inf

But for the same expression, I am able to get the value from python,

$ python
>>> pow(2,2000)

Can any body help me with that option?

posted Sep 13, 2013 by Bob Wise

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote

There is no GCC option that will help you here. Python and C are two different languages and they represent numbers in different ways. To do this kind of thing in C you will need to use some sort of bignum library, such as libmpfr.

answer Sep 13, 2013 by Kumar Mitrasen
+1 vote

I would suggest you have a look at the Gnu MP library, which deals with big integers, floats and gives you lots of things that you can normally find in languages like Python, Go or Java.

An example would be:

 mpz_t a;
 mpz_set_str(a, "10000000000000000000000000000", 10);
 gmp_printf("%Zd", a);

which will print this number back to you, and %Zx will print the Hex version of it.

answer Sep 13, 2013 by Garima Jain
Similar Questions
+1 vote

I am trying to compile a simple c/c++ code using g++. The binary carried more information(symbols). Then I used the option -O3 to get a more optimized code but still there seems to be some information(symbols) not mandatory for the binary execution. I need to use 'strip' command to remove those information.

I felt there must be some gcc/g++ option to get this stripping as part of compilation & linking itself. Can anyone help me with this?

0 votes

Can I use gcc as well as java compiler on a single desktop?

+1 vote

I don't really understand this option. I enabled it but it warns for essentially all of my classes which have any virtual methods. For
example if I have Foo.h:

 class Foo {
 virtual bool bar();

then Foo.cpp which implements Foo. And then in another header somewhere else I inherit from Foo and implement bar() differently (as a virtual function). However when GCC compiles Foo.cpp it can't see the other header, so I guess it assumes no one inherits from Foo and suggests it should be marked final:

Declaring type 'class Foo' final would enable devirtualization of N calls

I mean sure, it would, but that would defeat the entire point (as I understand it).

I don't really understand how/where this option is meant to be used.
Ditto for -Wsuggest-final-methods.

0 votes

I'm studying about C compiler for increasing software quality. So I want to get all of compile error message list of gcc about C language. I was trying to find it. But I can't find it anywhere. How can I find it?

Please help?

Useful Links with Similar Problem
Contact Us
+91 9880187415
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.