Re: the funtion to judge devisible or not

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu Dec 09 2010 - 14:05:28 MST

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
Received on Thu Dec 9 14:05:35 2010

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