Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

numerical constant definition does not work !

numerical constant definition does not work !

numerical constant definition does not work !

hello everybody,

during an intense programming session I stumbled accross a very strange problem. Have a look at the following simple program:

program test

    implicit none
    real(kind(1.0d0)), parameter :: real_const = 3.14159265358979
    real(kind(1.0d0)) :: real_variable
    real(kind(1.0d0)) :: real_variable_readin
    character(128) :: real_char
    real_char = '3.14159265358979'
    real_variable = 3.14159265358979
    read(real_char,*), real_variable_readin
    write(*,*), real_variable
    write(*,*), 2*acos(0.0d0)
    write(*,*), real_variable_readin
end program test

The Ouptput should be three times the same value:


BUT IT IS NOT --> on my computer the output looks like this:


I'm using g95 (newest version 2005-07-14) on a dual opteron workstation running under linux ...

Can anybody tell me what's going on ...



RE: numerical constant definition does not work !

The * in the read statement assumes G format which probably defaults to real instead of double precision.  You probably need to specify something like F17.15

RE: numerical constant definition does not work !

... I'm happy with the behaviour of the read statement, the problem is the output of the real_variable = 3.14159265358979 which should give


but instead it gives


... ???

RE: numerical constant definition does not work !

Consult your compiler docs: what's a type of float literals. It seems you have real*4 value. Add D0 in


real_variable = 3.14159265358979D0
and try again.

It's in C/C++ languages float literals have a type of double. I don't remember what's its type in Fortran, but it does not depend on the left side of assignment, of course.

RE: numerical constant definition does not work !

... thank you, this did the trick ... ))))))))))))

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close