- #1
Cbuha
- 2
- 0
I ran into a kind of strange thing today while coding. I needed Pi in a program, so I used 2*accos(0.0) to pull it out, but my answers were slightly off. I checked the Pi calculated and it was off after a few decimal places.
"Odd", I thought, and just decided to put in Pi as an assigned number. However, this still didn't solve the problem! No matter how I inputted it, it was being altered somehow by the program. I whipped up a really quick program to demonstrate what I'm talking about.
program probs
real(kind=8)::v
v=3.141592653589793238462643
write(*,*)v
end
if you check the output( assuming it's not just my machine or compiler for some reason) you'll see the values for v and the number inputted for it are not the same.
I'm guessing it has something to do with using the kind flag, but I'm not much of a comp sci person, and my searches didn't turn up anything useful. Anyone have any clue how to fix this? If it is related to kind, how can I keep high precision while avoiding this problem?
"Odd", I thought, and just decided to put in Pi as an assigned number. However, this still didn't solve the problem! No matter how I inputted it, it was being altered somehow by the program. I whipped up a really quick program to demonstrate what I'm talking about.
program probs
real(kind=8)::v
v=3.141592653589793238462643
write(*,*)v
end
if you check the output( assuming it's not just my machine or compiler for some reason) you'll see the values for v and the number inputted for it are not the same.
I'm guessing it has something to do with using the kind flag, but I'm not much of a comp sci person, and my searches didn't turn up anything useful. Anyone have any clue how to fix this? If it is related to kind, how can I keep high precision while avoiding this problem?