Programming-Idioms

Implementation
Fortran

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Implementation edit is for fixing errors and enhancing with metadata.

Instead of changing the code of the snippet, consider creating another Fortran implementation.

Other implementations
long y = Math.round(x);
y = (x + 1/2r).floor
import std.math: round;
int y = cast(int) x.round;
y = floor (x + 1/2)
import "math"
y := int(math.Floor(x + 0.5))
var
  y: integer;
  x: double;
begin
  y := round(x);
end.
#include <math.h>
int y = (int)floorf(x + 0.5f);
#include <cmath>
int y = static_cast<int>(std::floor(x + 0.5f));
$y = (int) round($x);
my $y = int($x + 1/2);
let y = x.round() as i64;
y = Float.round x
function round(float)
    local int, part = math.modf(float)
    if float == math.abs(float) and part >= .5 then return int+1    -- positive float
    elseif part <= -.5 then return int-1                            -- negative float
    end
    return int
end
var y = Math.round(x);
function round(float)
    return math.floor(float + .5)
end
y = int(x + 0.5)
int x = Math.Round(y);
(define y (round x))
y = x.round();