LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Datatype problem in project euler

Today I had nothing to do, so I participated in Project Euler http://projecteuler.net with Labview. I'm at question 10 now. The question itself isn't much of a challenge, but the problem I'm having is that the datatypes are to small for the value I would like to put in there. The value first goes up, then changes from + to - and then goes back to zero. This all happens while I'm just adding up to the value.

 

I guess there is a sollution to this problem but I don't seem to find it. Is there someone who can and will help me please?

0 Kudos
Message 1 of 5
(2,722 Views)
What datatypes are you trying to use?  Are they integer or floating point?  How many bytes?
0 Kudos
Message 2 of 5
(2,700 Views)

For example:

 

Calculate the full value of 2^1000. Even if I use the 64bit datatype I come in (very) short.

 

Thank you very much for your response!

0 Kudos
Message 3 of 5
(2,690 Views)

by the way, I am using integers because the result has to be accurate. In the end I need the sum of all numbers of the result.

 

(example: 456789 becomes 4+5+6+7+8+9 = 39 and the 39 is what I need)

0 Kudos
Message 4 of 5
(2,681 Views)

Well, the link you gave said problem 10 was "Find the sum of all the primes below two million", a little different problem than 2^1000.

 

In order represent 2^1000 at full resolution, you would need a 1000 bit number!  Of course a U64 won't be able to hold it.  A double will hold it and it comes to about 1.07...e301, so 301 decimal digits.  But a double won't store the full resolution.

 

In order to do what you want, you will have to set up your own math functions using 125+ bytes.  You will have to do the multiplication and do all of your own carries.  That why they made it a problem, to challenge you to figure out the algorhitm to do it.  Otherwise going 2^1000 in any programming language is a trivial exercise.

0 Kudos
Message 5 of 5
(2,671 Views)