Jump to content

i think my double is to small

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
Nille

Nille

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Hi mates ive made a program that is supposed to count 93^16 and its really not a complicated program.

But i have this small problem when it is going to write 74805201 it writes 7.48052e+007 and i know its some really clever formula or something.

Does anyone know of a way for me to get it to write the digits and not the formula. (it needs to be able to handle 2.70828e+035 and if possible 9.80515e+062)

And if you feel like it could you please explain how that formula thing works or maybe give me a link to a page where i can read a bit about it.

P.S Thanks for any help on forehand and if you want me to post the code just write so.

#2
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
I can't explain the formula (look complicated) but I think using a long double would solve your problem.

Is a float or double larger?

#3
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
You won't be able to count in 1's via a floating point representation because there's a limit on precision. The floating point numbers are ordered float (or single precision float), double, and long double in terms of both precision and range of representable numbers.

Floating point - Wikipedia, the free encyclopedia

For integers of that size you really want an infinite precision number which doesn't exist in standard C or C++. Unsigned 64bit integers can go up to ~10^19. You can either create a class to handle infinite precision integers (including output) if you are using C++. For C you could achieve the same but I'd be messier. Personally I'd look at a moth mathematical oriented language like Haskell. Developing an infinite precision integer in C/C++ is going to be messy and require a whole lot of memory management.

#4
Nille

Nille

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
So basicly use smaller numbers or use another langage? :P

#5
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Like G_Morgan said, you can't represent numbers as big as 31313180170800116587336013460801, which 93^16 is, with standard-C++-types. You need to fix some solutions yourself, or use some of the many big-integer libraries for C++. Use some search engine, and you'll find something fast.

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
If you use the GMP library, you will be able to accomplish what you want.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
I didn't think you understood what '7.48052e+007' meant. Just to clarify, it means the number 7.48052 x 10^7 (move the decimal 7 places to the right ->) or 7.4805200. Though you'd like to know :)

#8
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts

Victor said:

I didn't think you understood what '7.48052e+007' meant. Just to clarify, it means the number 7.48052 x 10^7 (move the decimal 7 places to the right ->) or 7.4805200. Though you'd like to know :)

Not to be pedantic but you mean 74805200 ;).

#9
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
Yes, sorry for the typo.