I do not understand the output of FRACTION(), for example
write(*,*) fraction(553.334)
It gives me 0.5403652
.
I thought it should return 0.334
, as 553.334-floor(553.334)
does. What is wrong in my understanding?
Au contraire, that value is exactly (within the limits of precision available) the right answer. I think the error is that you have misunderstood what fraction
does. To paraphrase the standard (widely available online, as are many tutorials and other guides) fraction(x)
returns the fractional part of the model representation of x
. The model representation of x
is, on most modern computers, a number of the form x*2^-k
. In effect the function returns the number x
divided by the next highest power of 2, in the case of your example 553.034/1024 == 553.034*2^-10
.
As ever in computing, RTFM (Read The Fortran Manual).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With