After doing some digging, I came to the following result:
The cut off after the 7th digit came from not initializing pi correctly
wrong: real(rk) :: pi = 3.14159265358979323846264338327950288419716939937510582
correct: real(rk) :: pi = 3.14159265358979323846264338327950288419716939937510582_rk...
Yes, I am aware that many of the digits get lost right away, I just copied them in and was too lazy to delete the obsolete ones. And about the output: my mistake! Again, I didn't count the digits and didn't think that write(*,*) prints irrelevant digits. My output looks like this...
Hello salgerman,
thank you for your explanation. I understand all the above and of course I understand that I do not gain precision by converting an integer into a real. Actually I just wanted to know, if there was an easy way to convert an integer into a selected_real_kind. This is why i did...
You are right, the integer has to be in the numerator, but my question is still the same.
This is a minimal example:
program conversion
implicit none
integer, parameter :: rk = selected_real_kind(15,307)
integer :: a = 10, b = 5
real(rk) :: c
!integer division but integer output ->...
Hello,
I want to convert an integer variable into a selected_real_kind but I am not sure how to do this. Can anyone help me? The code looks like this:
integer, parameter :: rk = selected_real_kind(15,307) !in this case double precision
integer :: a = 10
real(rk) :: b
b = 1._rk/a !here I get...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.