 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Fri May 16, 2025 8:58 am Post subject: Fortran 2023 trig functions |
|
|
The fortran 2023 standard includes new trig related functions, namely cosd, sind, tand, acosd, asind, atand, atan2d, acospi, asinpi, atanpi, atan2pi, cospi, sinpi, and tanpi.
**D functions which use degrees rather than radians were implemented in gFortran and Ifort as extensions long before the 2023 standard, so they do appear fairly regularly in code I see written by others.
**PI functions operate on multiples of half revolutions. For example:: COSPI(x) = COS(PI*X), so COSPI(1.0) = -1.0 These functions have obvious applications in signal processing etc.
Perhaps these new intrinsics should be added to the FTN95 wish list, and added to the library when time permits? This would keep the core mathematical intrinsics in FTN95 in synch with the latest fortran standard.
The functions should be easy to implement - no gotchas like asin(Z)
Further details can be found here:
https://wg5-fortran.org/N2201-N2250/N2212.pdf |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Sat May 17, 2025 6:46 am Post subject: |
|
|
Many thanks for the feedback. I have added this to the wish list. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Thu Jun 05, 2025 8:24 am Post subject: |
|
|
These functions have now been implemented for the next release of FTN95 and the associated DLLs. |
|
Back to top |
|
 |
wahorger

Joined: 13 Oct 2014 Posts: 1257 Location: Morrison, CO, USA
|
Posted: Thu Jun 05, 2025 1:54 pm Post subject: |
|
|
Paul, this will be a nice addition. I have some complex equations that will be simplified (to the eye, at least) using these new features.
Thanks for all you do! |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Thu Jun 05, 2025 5:04 pm Post subject: |
|
|
Bill
If "complex" means passing and returning complex numbers then this addition will not help.
As I understand it, the Standard does not include complex numbers in this context. Please let me know if I am wrong. |
|
Back to top |
|
 |
wahorger

Joined: 13 Oct 2014 Posts: 1257 Location: Morrison, CO, USA
|
Posted: Thu Jun 05, 2025 11:17 pm Post subject: |
|
|
Oh, sorry! I "misspoke". I meant that there are a number of calculations that would be better done using *D or *PI functions, making the reading of them simpler, versus complex. Mostly involving spherical trig and datum conversions...
I can certainly see using that term would cause some concern! |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Fri Jun 06, 2025 8:23 am Post subject: |
|
|
Good work Paul, I appreciate this addition to the library.
Just to clarify, the aforementioned functions are indeed intended to operate on real and not complex variables. |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Wed Jun 25, 2025 12:22 pm Post subject: |
|
|
Paul, there's something not correct with the *d functions. The following code should return two columns of data with equal entries in each row.
Code: | program test
use iso_fortran_env
implicit none
real :: rad2deg
real x
real*8 xd
write(*,*) compiler_version()
x = 45.0
write(*,'(2(F8.5,1X))') sind(x), sind(45.0)
write(*,'(2(F8.5,1X))') cosd(x), cosd(45.0)
write(*,'(2(F8.5,1X))') tand(x), tand(45.0)
x = 0.0
write(*,'(2(F8.5,1X))') asind(x), asind(0.0)
write(*,'(2(F8.5,1X))') acosd(x), acosd(0.0)
write(*,'(2(F8.5,1X))') atand(x), atand(0.0)
xd = 1.d0
write(*,'(2(F8.5,1X))') asind(xd), asind(1.d0)
write(*,'(2(F8.5,1X))') acosd(xd), acosd(1.d0)
write(*,'(2(F8.5,1X))') atand(xd), atand(1.d0)
end program test |
Code: | FTN95 v9.13
0.70711 0.85090
0.70711 0.52532
1.00000 1.61978
0.00000 0.00000
90.00000 1.57080
0.00000 0.00000
90.00000 1.57080
0.00000 0.00000
45.00000 0.78540 |
Code: | GCC version 12.3.0
0.70711 0.70711
0.70711 0.70711
1.00000 1.00000
0.00000 0.00000
90.00000 90.00000
0.00000 0.00000
90.00000 90.00000
0.00000 0.00000
45.00000 45.00000 |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Wed Jun 25, 2025 2:02 pm Post subject: |
|
|
Thanks Ken. I will take a look at this. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Thu Jun 26, 2025 9:15 am Post subject: |
|
|
This has now been fixed for the next release of FTN95. |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Thu Jun 26, 2025 2:03 pm Post subject: |
|
|
Thanks Paul,
Did you also look at the *pi functions? I see today that they have a similar issue.
Code: | x = 1.0
print*, asinpi(x), asinpi(1.0)
print*, atanpi(x), atanpi(1.0)
x = 0.0
print*, acospi(x), acospi(0.0)
print*, atanpi(x), atanpi(0.0)
end |
Code: | 0.500000 1.57080
0.250000 0.785398
0.500000 1.57080
0.00000 0.00000
C:\Arcadis 2025\0008 |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Thu Jun 26, 2025 3:07 pm Post subject: |
|
|
Yes and also a failure when used in an initialisation (PARAMETER) statement. |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2403 Location: Yateley, Hants, UK
|
Posted: Tue Jul 01, 2025 7:44 pm Post subject: |
|
|
I am fascinated by the introduction of new functions like this. What did people do before? What did they name their self-developed functions? Is there any conflict - and do the system functions perform better (faster? more accurate?)? |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8217 Location: Salford, UK
|
Posted: Tue Jul 01, 2025 8:59 pm Post subject: |
|
|
As I understand it, in general there is no reason to expect faster or more accurate results. Any differences will normally be in the round-off error.
But there are some interesting possibilities. For example cosd(60.0) could be exactly 0.5 with no round-off error, whilst tand(90.0) could print as INFINITY. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|