mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Adding Interactive Data Language (IDL) support.
This commit is contained in:
42
samples/IDL/mg_trunc.pro
Normal file
42
samples/IDL/mg_trunc.pro
Normal file
@@ -0,0 +1,42 @@
|
||||
; docformat = 'rst'
|
||||
|
||||
;+
|
||||
; Truncate argument towards 0.0, i.e., takes the `FLOOR` of positive values
|
||||
; and the `CEIL` of negative values.
|
||||
;
|
||||
; :Examples:
|
||||
; Try the main-level program at the end of this file. It does::
|
||||
;
|
||||
; IDL> print, mg_trunc([1.2, -1.2, 0.0])
|
||||
; 1 -1 0
|
||||
; IDL> print, floor([1.2, -1.2, 0.0])
|
||||
; 1 -2 0
|
||||
; IDL> print, ceil([1.2, -1.2, 0.0])
|
||||
; 2 -1 0
|
||||
;
|
||||
; :Returns:
|
||||
; array of same type as argument
|
||||
;
|
||||
; :Params:
|
||||
; x : in, required, type=float/double
|
||||
; array containing values to truncate
|
||||
;-
|
||||
function mg_trunc, x
|
||||
compile_opt strictarr
|
||||
|
||||
result = ceil(x)
|
||||
posInd = where(x gt 0, nposInd)
|
||||
|
||||
if (nposInd gt 0L) then begin
|
||||
result[posInd] = floor(x[posInd])
|
||||
endif
|
||||
|
||||
return, result
|
||||
end
|
||||
|
||||
|
||||
; main-level example program
|
||||
|
||||
print, mg_trunc([1.2, -1.2, 0.0])
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user