-2

I'm currently trying to make a simple calculator, but I want it to use somewhat big numbers(anything above 10^10 should do). And since any decent calculator has floating point operations, I decided to use double as my type. Sadly, when I tried to write a big number(around 10^7), it went into e notation. I want to display it like a normal number.

All help is appreciated. :D

  • 1
    Also, `double` can carry more than 16 significant decimal digits, you should paste some code with your actual operations. – Iban Cereijo Mar 09 '14 at 19:57
  • Simple float has its limit at 10^37 . You should have some other problem. – peterh Mar 09 '14 at 19:58
  • Maybe your printing function trims the decimals? – Sebastian Hoffmann Mar 09 '14 at 19:59
  • Correction, it doesn't do out of limits, rather it goes into E notation around 10^7. Sorry for the mistake >. – user3399371 Mar 09 '14 at 19:59
  • @user3399371 And you dont want scientific notation? – Sebastian Hoffmann Mar 09 '14 at 20:00
  • No, I want a normal number up to around 10^15. Then I want it in notation, similar to how Windows' Calculator works. – user3399371 Mar 09 '14 at 20:01
  • @user3399371 I think you missunderstand something here. It stays a "normal" number. Consider `10^3 = 1000`, though represented in two ways, its the same number. Your question isnt about precision but about printing doubles/floats. So I advise you either to edit your question in order to make your intention clear or to delete it and create a new one stating your actual problem. Please dont forget to include your printing code. – Sebastian Hoffmann Mar 09 '14 at 20:03
  • -1 Please explain clearly in the question what the problem is. Show code, and as a clear and direct question. – David Heffernan Mar 09 '14 at 20:10

2 Answers2

1

If you want to display all digits of your double (instead of going into scientific notation), you have to change your output stream's float formatting to std::fixed:

Live demo on Coliru:

double d = 1000000000000000.0; // 10^16
std::cout << std::fixed << d;

Output:

1000000000000000.000000

If you want your display to go into scientific notation at a custom exponent, you'll have to do that yourself using the existing tools.

user703016
  • 37,307
  • 8
  • 87
  • 112
0

You could try out GMP library for for arbitrary precision arithmetic. If you're using it on Windows you can neatly install it using mingw-get.

For 64bit double you could use long double, I think. I have personally never needed this.

And also there are processor extensions for longer floating point registers which I don't know much about and take a bit of effort to use for trivial tasks.

Ivarpoiss
  • 1,025
  • 1
  • 10
  • 18