Fortran Why Doesn't Fortran Recognize Small Numbers?

  • Thread starter Thread starter womfalcs3
  • Start date Start date
  • Tags Tags
    Fortran Numbers
Click For Summary
The discussion revolves around issues with numerical precision in Fortran, specifically when using the gfortran compiler. A user encounters problems with a function f(y) that should return a specific value but instead outputs zeros when a small coefficient (1E-5) is used. The user notes that changing the coefficient to 1 yields the correct result, suggesting a potential issue with data type precision. It is highlighted that using a low precision data type, such as a single precision real (4 bytes), could lead to this problem. The conversation shifts to the importance of double precision in calculations, with the user successfully incorporating double precision statements to resolve the issue. Additionally, there is a query about redefining functions after input type statements, indicating a desire for flexibility in function definitions throughout the program.
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.
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

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