Why Doesn't Fortran Recognize Small Numbers?

  • Context: Fortran 
  • Thread starter Thread starter womfalcs3
  • Start date Start date
  • Tags Tags
    Fortran Numbers
Click For Summary

Discussion Overview

The discussion revolves around issues related to numerical precision in Fortran, specifically concerning the recognition and handling of small numbers in calculations. Participants explore potential causes for unexpected results when using small coefficients in mathematical functions, as well as questions about function definitions in the context of Fortran programming.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant reports that using a small coefficient (1E-5) in a function results in zero output when compiled with gfortran, suggesting a potential issue with the compiler or data type precision.
  • Another participant suggests that the problem may stem from using a low precision data type, such as real (4 bytes), or from type mismatches that could lead to demotion of types.
  • A later reply indicates that incorporating double precision statements resolved the issue, implying that precision was indeed a factor.
  • Another participant inquires about the possibility of redefining functions after input type statements, seeking clarification on function definitions within the program structure.

Areas of Agreement / Disagreement

Participants generally agree that precision issues are likely at play, but there is no consensus on the exact nature of the problem or the best approach to defining functions in Fortran.

Contextual Notes

Limitations include potential missing assumptions about data types and precision settings, as well as the specific context of the Fortran version being used, which may affect functionality.

Who May Find This Useful

Programmers working with Fortran, particularly those dealing with numerical computations and precision issues, as well as those interested in function definitions within Fortran programs.

womfalcs3
Messages
60
Reaction score
5
We're not talking very small. Is it the compiler? I'm using gfortran.

An example would be:

f(y)=1E-5*(y**3)

For f(40), that should be 0.64. When I compile and execute, however, it displays 0's.

If I make the coefficient 1, the result does come out to be correct.


I have an old Fortran IV (I'm using F77) book that says for that version of the code, I can't do 1.E-76.

This is well closer to 1 than that. They even used an example where the power of 10 was -21. So is this right? Is it a problem with the compiler?
 
Technology news on Phys.org
It sounds like your problem is one of the following things:
You are using too low a precision data type, perhaps real (4 bytes) and not double...
Your types are mismatched and it's demoting types...
There's some other problem.

I think you'd get more feedback with more context.
 
Ah double precision statements. I didn't think of that. I was trying to use periods, which weren't working, but I've seen people use them for that purpose.

Thank you. I read up on double precision statements and it was simple enough to incorporate.

That worked.
 
Rather than make a new thread, I figured I'd ask here.

Is there anyway to define functions after the input type statements?

For example, f(x)=sin(x). I want to redefine f(x) as I go along the program.

Thanks.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
8K
Replies
7
Views
3K
Replies
7
Views
3K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
17K