Why Doesn't Fortran Recognize Small Numbers?

  • Context: Fortran 
  • Thread starter Thread starter womfalcs3
  • Start date Start date
  • Tags Tags
    Fortran Numbers
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 4K views
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?
 
Physics 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.