Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:47:11+00:00 2026-06-04T07:47:11+00:00

I’m getting some strange results from the log function in gfortran 4.5 (OSX) and

  • 0

I’m getting some strange results from the log function in gfortran 4.5 (OSX) and gfortran 4.7 (OSX).

The following program gives the unexpected results:

program test_log
  real(8) :: e = 2.7182818284590451_8
  write(*,*) 'log(2.7..)', log(2.7182818284590451_8)
  write(*,*) 'log(e)', log(e)
end program test_log

I run it like this:

gfortran-mp-4.5 ./test.f90  && ./a.out 
log(2.7..)   1.6249753165355076     
log(e)   1.0000000000000000

I expected both to be 1.0

Update:

program test_log
  real(8) :: e = 2.7182818284590451_8
  real(8) :: e2 = 2.7182818284590451D0
  real(8) :: e3 = exp(1.0)
  write(*,*) 'log(2.7..)', log(2.7182818284590451_8)
  write(*,*) 'log(e)', log(e)
  write(*,*) 'log(e2)', log(e2)
  write(*,*) 'log(e3)', log(e3)
end program test_log

gives

gfortran-mp-4.5 ./test.f90  && ./a.out 
 log(2.7..)   1.6249753165355076     
 log(e)   1.0000000000000000     
 log(e2)   1.0000000000000000     
 log(e3)   1.0188423211430429
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:47:14+00:00Added an answer on June 4, 2026 at 7:47 am
    program test_log
      integer, parameter :: Dbl_K = selected_real_kind (14)
      real(Dbl_K) :: e = 2.7182818284590451_Dbl_K
      real(Dbl_K) :: e2 = 2.7182818284590451D0
      real(Dbl_K) :: e3 = exp(1.0)
      real(Dbl_K) :: e4 = exp(1.0_Dbl_K)
      write(*,*) 'log(2.7..)', log(2.7182818284590451_Dbl_K)
      write(*,*) 'log(e)', log(e)
      write(*,*) 'log(e2)', log(e2)
      write(*,*) 'log(e3)', log(e3)
      write(*,*) 'log(e4)', log(e4)
    end program test_log
    

    Uses selected_real_kind instead of relying on 8 being the value for double.

    Output with gfortran 4.6 and 4.7 on a MacBook Pro with Snow Leopard is:

     log(2.7..)   1.0000000000000000     
     log(e)   1.0000000000000000     
     log(e2)   1.0000000000000000     
     log(e3)  0.99999996963214000     
     log(e4)   1.0000000000000000 
    

    The value for e3 is different from 1 because “exp(1.0)” has 1 as a single precision real.

    On my new Mac Air with Lion I get incorrect results. I have observed other problems gfortran on this machine.

    gfortran 4.6

     log(2.7..)   1.6249753165355076     
     log(e)   1.6249753165355076     
     log(e2)   1.6249753165355076     
     log(e3)   1.6438056251294211     
     log(e4)   1.6438055841322456
    

    gfortran 4.7

    log(2.7..)   1.6249753165355076     
     log(e)   1.0000000000000000     
     log(e2)   1.0000000000000000     
     log(e3)   1.0188423211430429     
     log(e4)   1.0188422801197137
    

    So the problem isn’t unique. Not sure what it is.

    P.S. On the MacAir compiler options change the output. I’m not sure which option or options matter.

    P.P.S.

    program test2_log
      real:: e = 2.7182818284590451
      real:: e2 = 2.7182818284590451D0
      real:: e3 = exp(1.0)
      real:: e4 = exp(1.0)
      write(*,*) 'log(2.7..)', log(2.7182818284590451)
      write(*,*) 'log(e)', log(e)
      write(*,*) 'log(e2)', log(e2)
      write(*,*) 'log(e3)', log(e3)
      write(*,*) 'log(e4)', log(e4)
    end program test2_log
    

    On the MacAir, gfortran 4.6 gives:

     log(2.7..)   1.3489696    
     log(e)  0.99999994    
     log(e2)  0.99999994    
     log(e3)   1.0188423    
     log(e4)   1.0188423 
    

    with the compiler option -fdefault-real-8 it changes to

     log(2.7..)   1.6249753165355076     
     log(e)   1.0000000000000000     
     log(e2)   1.0000000000000000     
     log(e3)   1.0188422801197137     
     log(e4)   1.0188422801197137
    

    It’s some defect in the installation.

    Edit: all gfortran versions on both machines are from MacPorts. Is the different the OS version or something else? Works on Snow Leopard, not on Lion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.