[small]Paul Laidler wrote:[/small]
*I have to admit that I do not understand your problem.
Are you saying that the following code does not give the correct double precision answer?
REAL(2) x, y
x = 0.3_2
y = sin(x)*
Essentially, yes. I wrote a routine to input an angle in degrees, convert to radians, and take the sine, cosine and tangent. For pi I declared it as a parameter with 19 digits of precision, then divided that by 180.0 for the degrees-to-radians conversion factor. The answers I get for 45 degrees, 60 degrees and 360 degrees are all off starting in the 8th significant digit -- i.e., where the end of the first four bytes comes. I'll post my code below. Sorry for the over-elaborate text to number conversion logic.
[pre]!=====
! Program to show use of intrinsic and user-written functions.
!=====
Program Trig
real(kind=2), parameter :: pi = 3.141592653589793
integer :: dotplace ! Location of decimal point.
integer :: ivalue ! Value as an integer.
character(len=6) :: MyFormat ! Conversion format, string to number.
character(len=80) :: reply ! The reply itself.
integer :: rlen ! Length of reply in characters.
real(kind=2) :: value ! Mathematical value of reply.
!-----
! Explain how the program works:
write(*, *) 'This program shows the result of using trig'
write(*, *) 'functions on values you enter. Enter angles'
write(*, *) 'in degrees. Enter BYE or QUIT to stop.'
write(*, *) ! This prints a blank line.
! Start loop by getting user input:
do
write(*, 10)
10 format('Value or stop code: ⇒', $)
read(*, *) reply
rlen = len_trim(reply)
call upcase@(reply)
! If reply is a quit code, quit:
if (reply == 'BYE' .or. reply == 'QUIT') then
write (*, *) 'Thanks. Bye now.'
exit ! Quit program.
! If reply is a number, convert it appropriately:
else
dotplace = index(reply, '.')
if (dotplace == 0) then ! No decimal point?
write(MyFormat, 20) rlen ! Use integer format.
20 format('(I', I1, ')')
read(reply, MyFormat) ivalue ! Convert string to number.
value = real(ivalue)
else
write(MyFormat, 30) rlen ! Use real number format.
30 format('(G', I1, '.1)')
read(reply, MyFormat) value ! Convert string to number.
end if
! Finally, do trig operations on the resulting value:
Call TrigStuff(value) ! Call subroutine.
end if
end do
contains
!=====
! TrigStuff applies the trig functions to the user-entered value.
!=====
subroutine TrigStuff(x)
real(kind=2) :: x
real(kind=2), parameter :: pi = 3.141592653589793238
real(kind=2), parameter :: DegToRad = pi / 180.0
real(kind=2) :: radians ! Angle in radians.
!-----
radians = x * DegToRad ! Convert to radians.
write(*, 10) x, real(dsin(radians))
write(*, 20) x, dcos(radians)
write(*, 30) x, dtan(radians)
10 format('Sine ', F10.5, ' = ', F12.9)
20 format('Cosine ', F10.5, ' = ', F12.9)
30 format('Tangent ', F10.5, ' = ', F12.9)
end subroutine TrigStuff
End Program Trig[/pre]