/usr/share/gnudatalanguage/astrolib/nint.pro is in gdl-astrolib 2018.02.16+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | function nint, x, LONG = long ;Nearest Integer Function
;+
; NAME:
; NINT
; PURPOSE:
; Nearest integer function.
; EXPLANATION:
; NINT() is similar to the intrinsic ROUND function, with the following
; two differences:
; (1) if no absolute value exceeds 32767, then the array is returned as
; as a type INTEGER instead of LONG
; (2) NINT will work on strings, e.g. print,nint(['3.4','-0.9']) will
; give [3,-1], whereas ROUND() gives an error message
;
; CALLING SEQUENCE:
; result = nint( x, [ /LONG] )
;
; INPUT:
; X - An IDL variable, scalar or vector, usually floating or double
; Unless the LONG keyword is set, X must be between -32767.5 and
; 32767.5 to avoid integer overflow
;
; OUTPUT
; RESULT - Nearest integer to X
;
; OPTIONAL KEYWORD INPUT:
; LONG - If this keyword is set and non-zero, then the result of NINT
; is of type LONG. Otherwise, the result is of type LONG if
; any absolute values exceed 32767, and type INTEGER if all
; all absolute values are less than 32767.
; EXAMPLE:
; If X = [-0.9,-0.1,0.1,0.9] then NINT(X) = [-1,0,0,1]
;
; PROCEDURE CALL:
; None:
; REVISION HISTORY:
; Written W. Landsman January 1989
; Added LONG keyword November 1991
; Use ROUND if since V3.1.0 June 1993
; Always start with ROUND function April 1995
; Return LONG values, if some input value exceed 32767
; and accept string values February 1998
; Use size(/TNAME) instead of DATATYPE() October 2001
;-
xmax = max(x,min=xmin)
xmax = abs(xmax) > abs(xmin)
if (xmax gt 32767) or keyword_set(long) then begin
if size(x,/TNAME) eq 'STRING' then b = round(float(x)) else b = round(x)
end else begin
if size(x,/TNAME) eq 'STRING' then b = fix(round(float(x))) else $
b = fix(round(x))
endelse
return, b
end
|