significant(3f) - [M_framework__approx] round val to specified number of significant digits
Synopsis
Description
Options
Examples
pure elemental function significant(val,digits,round)
real,intent(in) :: val integer,intent(in) :: digits character(len=*),intent(in),optional :: round real :: significant
Round real value to specified number of significant digits
val value to round digits number of significant digits to produce round Use the round edit descriptor RU UP : the value resulting from conversion shall be the smallest representable value that is greater than or equal to the original value RD DOWN : the value resulting from conversion shall be the largest representable value that is less than or equal to the original value RZ ZERO : the value resulting from conversion shall be the value closest to the original value and no greater in magnitude than the original value. RN NEAREST : modeis NEAREST,thevalueresulting from conversion shall be the closer of the two nearest representable values if one is closer than the other. If the two nearest representable values are equidistant from the original value, it is processor dependent which one of them is chosen. RC COMPATIBLE : the value resulting from conversion shall be the closer of the two nearest representable values or the value away from zero if halfway between them. RP PROCESSOR_DEFINED : rounding during conversion shall be a processor-dependent default mode, which may correspond to one of the other modes.
Sample program
program demo_significant use M_framework__approx, only : significant implicit none integer :: i real :: r, v character(len=*),parameter :: g=(*(g0.7,1x))Results:write(*,g)significant([8765.43210,0.1234567890],5)
write(*,*)default:,1.23456789012345 write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9]) write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9],RU),RU write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9],RD),RD write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9],RZ),RZ write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9],RN),RN write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9],RC),RC write(*,g)significant(1.23456789012345,[1,2,3,4,5,6,7,8,9],RP),RP end program demo_significant
> 8765.400 .1234600 > default: 1.234568 > 1.000000 1.200000 1.230000 1.235000 1.234600 1.234570 ... > 1.234568 1.234568 1.234568 > 2.000000 1.300000 1.240000 1.235000 1.234600 1.234570 ... > 1.234568 1.234568 1.234568 RU > 1.000000 1.200000 1.230000 1.234000 1.234500 1.234560 ... > 1.234567 1.234568 1.234568 RD > 1.000000 1.200000 1.230000 1.234000 1.234500 1.234560 ... > 1.234567 1.234568 1.234568 RZ > 1.000000 1.200000 1.230000 1.235000 1.234600 1.234570 ... > 1.234568 1.234568 1.234568 RN > 1.000000 1.200000 1.230000 1.235000 1.234600 1.234570 ... > 1.234568 1.234568 1.234568 RC > 1.000000 1.200000 1.230000 1.235000 1.234600 1.234570 ... > 1.234568 1.234568 1.234568 RP
Nemo Release 3.1 | significant (3) | February 23, 2025 |