2

In Fortran, I output the result of tanh(1) and I get the value 0.7615941763:

open(unit=2, file='test_digits.txt', ACTION="write") write(2, '(1000F14.10)')( real(tanh(1.0))) 

However, I now try to do the same in MatLAB and the output is 0.761594155955765. There is a difference at the 8th digit.

What is the reason for this precision-difference? Can I fix it somehow?

1 Answer 1

6

Matlab is using double precision by default, you are using single precision floats! They are limited to 7-8 digits... If you use double precision as well, you will get the same precision:

program test write(*,*) 'single precision:', tanh(1.0) write(*,*) 'double precision:', tanh(1.0d0) end program 

Output:

 single precision: 0.761594176 double precision: 0.76159415595576485 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.