[ncl-talk] toint function
Bill Ladwig
ladwig at ucar.edu
Thu Mar 1 09:49:43 MST 2018
Hi Sheng-Hung,
The underlying code simply does a cast in C to an integer (e.g. x = (int)
y). The reason that you're seeing this behavior is that the number 2003201.942
has too many digits for a float (float only has ~7 digits), so you need to
make this a double by adding the 'd' to the end. Unless you specify the
'd', NCL assumes a 4-byte float. It seems like this should be happening for
both examples, but that's a compiler/floating point implementation detail I
guess.
This should work they way you're expecting:
print(toint(2003201.932d))
print(toint(2003201.942d))
Hope this helps,
Bill
On Thu, Mar 1, 2018 at 8:29 AM, Sheng-Hung Wang <wang.446 at osu.edu> wrote:
> Hi
>
> How does function toint work?
>
> Here is my problem
>
> print(toint(2003201.932))
>
> print(toint(2003201.942))
>
> Accoring to NCL web page, toint should truncate any fractional part of
> vales, but I got 2003201 for 1st one, and 2003202 for 2nd one.
>
> I know I can replace toint to floor in this case. I just like to know
> what's really going on for the future.
>
> Thanks
>
> Sheng-Hung
>
> --
> ========================================
> Sheng-Hung Wang, PhD
> Polar Meteorology Group
> Byrd Polar and Climate Research Center
> The Ohio State University
> 1090 Carmack Road, Columbus, Ohio 43210
> Phone: (614) 292-1060
> Fax: (614) 292-4697
> email: wang.446 at osu.edu
> ========================================
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180301/835377c3/attachment.html>
More information about the ncl-talk
mailing list