Lawrence D'Oliveiro
2024-10-20 03:47:13 UTC
I see that the Fortran 2023 spec has added a bunch of parallel trig
functions that work in degrees.
I find this sort of thing unnecessary. It seems conventional to add
functions for converting between degrees and radians, but a simpler way is
to simply define a conversion factor for each angle unit. One conversion
factor is simpler than two functions for each angle unit.
So trig functions always work in radians. Supposing we have
real, parameter :: DEG = PI / 180
real, parameter :: CIRCLE = 2 * PI
real, parameter :: RAD = 1
Then
sin(x) -- sin of x in radians
sin(x * DEG) -- x is in degrees
atan2(y, x) -- arctangent is in radians
atan2(y, x) / DEG -- arctangent is in degrees
and we can furthermore have equivalences like
sin(90 * DEG) = sin(0.25 * CIRCLE) = sin(PI / 2)
(to within rounding error, of course)
and it is easy enough to add other units, e.g.
real, parameter :: GRAD = PI / 200
Anybody remember those?
functions that work in degrees.
I find this sort of thing unnecessary. It seems conventional to add
functions for converting between degrees and radians, but a simpler way is
to simply define a conversion factor for each angle unit. One conversion
factor is simpler than two functions for each angle unit.
So trig functions always work in radians. Supposing we have
real, parameter :: DEG = PI / 180
real, parameter :: CIRCLE = 2 * PI
real, parameter :: RAD = 1
Then
sin(x) -- sin of x in radians
sin(x * DEG) -- x is in degrees
atan2(y, x) -- arctangent is in radians
atan2(y, x) / DEG -- arctangent is in degrees
and we can furthermore have equivalences like
sin(90 * DEG) = sin(0.25 * CIRCLE) = sin(PI / 2)
(to within rounding error, of course)
and it is easy enough to add other units, e.g.
real, parameter :: GRAD = PI / 200
Anybody remember those?