View previous topic :: View next topic |
Author |
Message |
stfark1
Joined: 02 Sep 2008 Posts: 228
|
Posted: Wed Dec 18, 2024 11:37 pm Post subject: asin of angle |
|
|
Note: in Silverfrost Fortran, 64 bit with Win11, when calling the function ASIN(A) and A=1.D0, get "invalid floating point operation". The limits for A, per the mathematical functions for Silverfrost Fortran, are stated as -1.D0 <= A <= 1.D0. Should this not be an "invalid floating point operation? As a minimum, I would think that Silverfrost Fortran should be checking this limit to make sure that it is not stated as invalid. Sid Kraft |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2611 Location: Sydney
|
Posted: Thu Dec 19, 2024 1:03 am Post subject: |
|
|
My test on Win 10
Code: | use iso_fortran_env
real*8 :: a
write (*,*) compiler_version ()
write (*,*) compiler_options ()
a = asin (1.0d0)
write (*,*) a
end
FTN95 v9.04.0
64;ECHO_OPTIONS;ERROR_NUMBERS;IMPLICIT_NONE;INTL;LINK;LOGL;NO_BANNER;UNLIMITED_ERRORS;VS7;
1.57079632679 |
I would check SET PATH |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8119 Location: Salford, UK
|
Posted: Thu Dec 19, 2024 8:59 am Post subject: |
|
|
Sid
I have tested John's code under Windows 11 (both 23 H2 and 24 H2).
I have also tested with /checkmate etc.
I have not been able to reproduce your error report.
Please supply a sample program that demonstrates the fault together with details of the FTN95 version that you are using. |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 777 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Thu Dec 19, 2024 11:25 am Post subject: |
|
|
Consider this simple example:
Code: | program p
implicit none
real*8 :: y
y = 1.d0
print*, y
print*, asin(y)
y = 1.d0 + epsilon(1.d0) ! Y is now ever so slighty greater than 1
! (as may happen in a real calculation where
! the expect value is exactly 1.d0)
print*, y ! Not obvious when you print the value.
print*, asin(y) ! Invalid float error!
end program p |
One way around this problem is to do the following:
Code: | program p
implicit none
real*8 :: y
y = 1.d0
print*, y
print*, asin(y)
y = 1.d0 + epsilon(1.d0) ! Y is now ever so slighty greater than 1
! (as may happen in a real calculation where
! the expect value is exactly 1.d0)
print*, y ! Not obvious when you print the value.
print*, limited_arg_asin(y) ! Call a function which truncates y to valid
! valid range and then returns the arcsine
contains
function limited_arg_asin(x) result (x1)
real*8, intent(in) :: x
real*8 :: x1
if(x .gt. 1.d0) then
x1 = 1.d0
else if (x .lt. -1.d0) then
x1 = -1.d0
else
x1 = x
end if
x1 = asin(x1)
end function limited_arg_asin
end program p |
|
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 777 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Thu Dec 19, 2024 12:11 pm Post subject: |
|
|
Alternative function without block ifs:
Code: | program p
implicit none
real*8 :: y
y = 1.d0
print*, y
print*, asin(y)
y = 1.d0 + epsilon(1.d0)
print*, y
print*, Dasin_t(y)
contains
function Dasin_t (y) result (asiny)
real*8 :: asiny
real*8, intent(in) :: y
real*8 :: x
x = max(y,-1.d0)
x = min(x, 1.d0)
asiny = asin(x)
end function Dasin_t
end program p |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8119 Location: Salford, UK
|
Posted: Thu Dec 19, 2024 12:39 pm Post subject: |
|
|
FTN95 has now been fixed for the next release so that an argument that is out of bounds will give a meaningful runtime failure message (as already occurs for Win32). |
|
Back to top |
|
 |
|