Silverfrost Forums

Welcome to our forums

Extension to iso_fortran_env

24 Dec 2023 4:15 #30893

Hello.

There does not appear to be support for ieee_arithmetic in the current ftn95 e.g.

program ieee
    use, intrinsic :: iso_fortran_env, only: wp=>real64
    use, intrinsic :: ieee_arithmetic
    implicit none

    print *, ieee_value(1.0_wp, ieee_positive_inf)
    print *, ieee_value(1.0_wp, ieee_negative_inf)
end program ieee

This might be handy to have in a future release to deal better with coding infinity into mathematical functions. For infinity I just set a very large number as a break point.

Lester

27 Dec 2023 8:23 #30896

Lester

Thank you for the feedback. I have made a note of your suggestion.

This is a part of the 2003 Standard that has not yet been implemented in FTN95.

At the moment computing z = 0.0 then v = 1.0/z will raise a runtime time exception as will v = z/z. This default exception handling will need to be changed when implementing the ieee_arithmetic module and this could be unsafe if the programmer is not fully aware if the implications.

13 May 2024 7:15 #31346

The next release of FTN95 and its associated DLLs will provide support for the Fortran 2003 intrinsic IEEE_ARITHMETIC module. This is particularly for x64, with some support for Win32.

A new routine TRAP_FP_EXCEPTIONS@ will be released for x64 but not for Win32.


SUBROUTINE TRAP_FP_EXCEPTIONS@(trap) INTEGER trap A trap value of zero masks all floating point runtime exceptions. A non-zero value restores the default state where floating point exceptions lead to a runtime failure.

This routine is not provided for Win32 because the the existing TRAP_EXCEPTION@ function does not enable progression (i.e. the CONTINUE_EXECUTION return state) after handling a floating point exception.

  1. TRAP_FP_EXCEPTIONS@ is implemented independently of the IEEE_ARITHMETIC module.
  2. Standard PRINT and WRITE statements will display 'NaN', 'Infinity', or '-Infinity' where appropiate (depending on the field width) and this is independent of IEEE_ARITHMETIC. The current output is '????....'.
  3. Users who want to mask floating point exceptions must use x64 and must call TRAP_FP_EXCEPTIONS@(0) for related sections of their code.

Example

real t,z,v(6) z = 0.0 t = tiny(z) call trap_fp_exceptions@(0) v = [z/z,z/1.0,-z/1.0,1.0/z,-1.0/z,t/10] call trap_fp_exceptions@(1) do i = 1,6; print*, v(i); end do end

Output:

NaN 0.00000 0.00000 Infinity -Infinity 0.00000

27 Dec 2024 2:47 #31760

The new IEE_ARITHMETIC module now gives support from +/- infinity (as of ftn85 v9.05)

program ieee use, intrinsic :: iso_fortran_env, only: wp=>real64 use, intrinsic :: ieee_arithmetic implicit none

print *, ieee_value(1.0_wp, ieee_positive_inf)
print *, ieee_value(1.0_wp, ieee_negative_inf)

end program ieee

Output:

Infinity -Infinity

Lester

Please login to reply.