comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: roundoff function in PV-WAVE
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: roundoff function in PV-WAVE [message #2958] Fri, 21 October 1994 08:09
landers is currently offline  landers
Messages: 45
Registered: May 1993
Member
I can only assume what ROUND does. Seems obvious tho...


In PV-WAVE:

NINT - Rounds to nearest integer or long. Basically does
FIX( number +/- 0.5 ), [+/- depends on sign of number).
Note that the User library version available in versions 4.2 and
before don't work right (for negative numbers).
Std lib version in version 5.0 is good.

If you want to round to a particular number of decimal points, do something
like:

rounded = NINT( number * 10^dig ) / 10^dig

where

number is the number (float or double) you want to round.

dig is an integer or long with the number of digits to the right of the
decimal point. Could even be negative (for left of decimal point).

Include the /Long keyword to NINT (v 5.0) if you want it to return a LONG
integer rather than a FIX (usually a good idea when converting from FLOATs
or DOUBLEs).

I realize that many of you may not have version 5.0 yet. Just be patient -
it's on the way (as soon as they dredge the newly-formed lake and find the
Houston shipping office)

Until that time, try this simple version:

function nint,n
;+
; i = NINT( a )
; returns the nearest integer to a, like FORTRAN's NINT func.
;-
on_error,2

n2 = fix( n + 0.5 )

neg = where( n lt 0, many )

if many ne 0 then n2(neg) = fix( n(neg) - 0.5 )

return, n2

end


;Dave
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ? Plot velocity field in distorted mesh ?
Next Topic: Test..Please Ignore.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 13:34:33 PDT 2025

Total time taken to generate the page: 0.80380 seconds