Fortran What is the correct way to assign a bound of magnitude 10**270 in Fortran?

  • Thread starter Thread starter autobot.d
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
To define a bound around magnitude 10**270 in double precision, an arithmetic overflow error occurs because 10**270 is evaluated as an integer expression, which exceeds the integer limit. To avoid this, it is recommended to use 10.0d0 ** 270 or simply 10.0d270, ensuring the use of a "d" exponent to indicate double precision. Using 10.0 ** 270 results in overflow as well, since 10.0 is treated as a single precision constant, which has a maximum representable value around 10**38.
autobot.d
Messages
67
Reaction score
0
I want to find a bound for around magnitude 10**270 which is within bounds of double precision but I get

DOUBLE PRECISION :: bound = 10**270

Error: Arithmetic overflow at (1)
.\q2.f03:70.4:


where 1 is beneath the first *.

I am sure it is something simple I am overlooking...
 
Technology news on Phys.org
Since 10 and 270 are both integers, 10**270 is evaluated as an integer expression, and then the result is converted to double precision to assign it to the variable. You got the overflow because 10**270 can't be represetned as an integer value.

You could write 10.0d0 ** 270, or better, just 10.0d270.

Note you must use a "d" exponent (not "e") in a constant to make it double precision. 10.0 ** 270 will still give an overflow, because 10.0 is a single precision constant and the maximum value that can be represented in single precision is about 1038.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
4
Views
2K
Replies
3
Views
3K
Replies
18
Views
6K
Replies
6
Views
2K
Replies
5
Views
3K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
11
Views
2K
Back
Top