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

  • Fortran
  • Thread starter autobot.d
  • Start date
  • Tags
    Fortran
In summary, the conversation discusses finding a bound within the double precision limits for a magnitude of 10**270. The error is caused by evaluating 10**270 as an integer expression instead of a double precision value. The solution is to use a "d" exponent in the constant or use 10.0d270.
  • #1
autobot.d
68
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
  • #2
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.
 

1. What is Fortran and how is it used?

Fortran is a programming language commonly used in scientific computing. It was designed specifically for mathematical and scientific calculations, and is often used in fields such as physics, engineering, and meteorology. Fortran is known for its high performance and ability to handle complex calculations.

2. Is Fortran still relevant in modern scientific research?

Yes, Fortran is still widely used in scientific research due to its speed and ability to handle large amounts of data. Many legacy codes and programs are still written in Fortran, and it continues to be updated and improved upon for modern use.

3. How does Fortran compare to other programming languages?

Fortran is different from more modern programming languages in that it is primarily used for scientific and mathematical calculations, rather than general purpose programming. However, it is still a powerful and efficient language for these specific tasks.

4. What are some common applications of Fortran?

Fortran is often used in fields such as atmospheric and climate modeling, computational fluid dynamics, and nuclear physics. It is also commonly used in scientific simulations and data analysis.

5. Is Fortran difficult to learn?

Fortran can be challenging to learn for those with no prior programming experience, as it has a specific syntax and structure. However, many resources and tutorials are available online to help beginners learn the language. Those with experience in other programming languages may find it easier to pick up Fortran.

Similar threads

  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
18
Views
6K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
Back
Top