Muhammad Usman Siddiqui

Greenhorn

Posts: 3

posted 3 years ago

The IEEE 754 specification, used by Java for floating point, specifies "infinity" as the largest possible positive value. Basically, when you overflow the double variable on the plus side, the variable becomes "infinity". This is different from integers, which use the twos complement representation, and wraps around to negative values on overflow.

Henry

- 1

Muhammad Usman Siddiqui wrote:

i believe my variable cant hold this value.

any suggestions?

The IEEE 754 specification, used by Java for floating point, specifies "infinity" as the largest possible positive value. Basically, when you overflow the double variable on the plus side, the variable becomes "infinity". This is different from integers, which use the twos complement representation, and wraps around to negative values on overflow.

Henry

Muhammad Usman Siddiqui

Greenhorn

Posts: 3

Muhammad Usman Siddiqui

Greenhorn

Posts: 3

posted 3 years ago

how can i fix it? can you point me to some where?

Henry Wong wrote:Muhammad Usman Siddiqui wrote:

i believe my variable cant hold this value.

any suggestions?

The IEEE 754 specification, used by Java for floating point, specifies "infinity" as the largest possible positive value. Basically, when you overflow the double variable on the plus side, the variable becomes "infinity". This is different from integers, which use the twos complement representation, and wraps around to negative values on overflow.

Henry

how can i fix it? can you point me to some where?

posted 3 years ago

- 1

you can't use a float. your solution is already there - us a BigInteger instead.

And quite honestly, you shouldn't be using a float anyway. You are working with integers, so you should use some kind of integer type.

And quite honestly, you shouldn't be using a float anyway. You are working with integers, so you should use some kind of integer type.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

posted 3 years ago

And, since one side of the sum of the numerator is less than 1, an approximation for F(4,000,000) is (1.618^4,000,000)/√5, which will have ≈ 832,000 digits. So: good luck with that!

Winston

fred rosenberger wrote:a quick search says that Fib(75) is approx. 2,111,485,077,978,049 You are trying to compute Fib(4,000,000). I'm not surprised it won't fit in a Float.

And, since one side of the sum of the numerator is less than 1, an approximation for F(4,000,000) is (1.618^4,000,000)/√5, which will have ≈ 832,000 digits. So: good luck with that!

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

It is sorta covered in the JavaRanch Style Guide. |