nearest in Fortran Wiki
## Description `nearest(x, s)` returns the processor-representable number nearest to `x` in the direction indicated by the sign of `s`. ## Standard [[Fortran 95]] and later ## Class [[Elemental procedure|Elemental function]] ## Syntax ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {: lang=fortran } result = nearest(x, s) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## Arguments - `x` - Shall be of type `real`. - `s` - Shall be of type `real` and not equal to zero. ## Return value The return value is of the same type as `x`. If `s` is positive, `nearest` returns the processor-representable number greater than `x` and nearest to it. If `s` is negative, `nearest` returns the processor-representable number smaller than `x` and nearest to it. ## Example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {: lang=fortran } program test_nearest real :: x, y x = nearest(42.0, 1.0) y = nearest(42.0, -1.0) write (*,"(3(g20.15))") x, y, x - y end program test_nearest ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ category: intrinsics
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル