Re: the funtion to judge devisible or not

From: H.Dang <danghy_at_nyahnyahspammersnyahnyah>
Date: Thu Dec 09 2010 - 15:37:37 MST

Hi Dave,

Thanks for these, I'm going to try them on my ncl.

Cheers
Hongyan
On Thu, Dec 9, 2010 at 4:05 PM, Dave Allured <dave.allured@noaa.gov> wrote:

> mac56:~ 1> ncl
> NCAR Command Language Version 5.2.1
> ncl 0> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> ncl 1> i = 2
> ncl 2> n = 10.0
> ncl 3> divisible = (mod(n,i) .eq. 0)
> ncl 4> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = True
> ncl 5> n = 7
> ncl 6> divisible = (mod(n,i) .eq. 0)
> ncl 7> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = False
> ncl 8> n = 9.9
> ncl 9> divisible = (mod(n,i) .eq. 0)
> ncl 10> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = False
> ncl 11> n = 10.1
> ncl 12> divisible = (mod(n,i) .eq. 0)
> ncl 13> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = False
> ncl 14> n = 999996
> ncl 15> divisible = (mod(n,i) .eq. 0)
> ncl 16> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = True
> ncl 17> exit
>
> The "where" function is just to get a clean print statement.
>
> Caution, this one-line method may seem to give the wrong answer if
> you exceed the precision of the data type. For example:
>
> ncl 1> i = 2
> ncl 2> n = 10.0000001
> ncl 3> divisible = (mod(n,i) .eq. 0)
> ncl 4> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = True
> ncl 5> n = 999999999
> ncl 6> divisible = (mod(n,i) .eq. 0)
> ncl 7> print ("divisible = "+where(divisible,"True","False"))
> (0) divisible = True
>
> --Dave
>
> On 12/9/2010 12:59 PM, H.Dang wrote:
> > Dear all,
> >
> > I was just wondering if NCL has a function to judge if a number is
> > devisible by another number. What I mean is: 10/2=5, where 5 is an
> > integer.
> >
> > Thanks for your help!
> >
> > --
> > Cordially,
> > Hongyan(鸿雁)
> > Tel: 1-519-8884567ext36667
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
Cordially,
Hongyan(鸿雁)
Tel: 1-519-8884567ext36667

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Dec 9 15:38:19 2010

This archive was generated by hypermail 2.1.8 : Fri Dec 10 2010 - 14:58:12 MST