Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Loss of precision in exponentiation - questions

$
0
0

Dear Fortran Masters, 

I have two simple questions.

1 - In the operation x**b, where b is always an integer. Is there any loss of precision if b is declared as real(8) or integer?

2 - In the operation x**b, where b is always real positive number. Is there any loss of precision if b is declared as real(8) or real(4)?

Why or why not? Kindly advise. Thank you, Javier

 

program powx

	implicit none

	real(8)	:: x
	real(8)	:: a
	real(4)	:: b
	integer	:: i

	x = 1.23456789d0
	i = 4
	a = 3d0
	b = 1.23456789

	! Question 1
	write (*,*) x**(i-1), x**dble(i-1), x**a, x**3.0

	! Question 2
	write (*,*) x**1.23456789, x**dble(1.23456789), x**x, x**b

end program powx

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>