From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>

Date: Fri, 10 Nov 2006 14:36:33 -0700 (MST)

Date: Fri, 10 Nov 2006 14:36:33 -0700 (MST)

*>Debasish Pai Mazumder wrote:
*

*>> I declared the value of Z in program which is given below,
*

*>>
*

*>> Z=2*(1.3806*10^(-23))^4/(((6.626*10^(-34))^3)*((3*10^8)^2))
*

*>>
*

*>> But I got a error massage "fatal:divide: Division by 0, Can't continue
*

*>> fatal:Div: operator failed, can't continue" in the above mentioned line.
*

*>>
*

*>> I guess this error occurs due to division by very low value.
*

*>>
*

*>> Is there any way to get rid of this error and compute the value of Z?
*

*>>
*

*>How about:
*

*>
*

*> ncl 7>
*

*>
*

Z=2*(1.3806*flt2dble(10^(-23)))^4/(((6.626*flt2dble(10^(-34)))^3)*((3*10^8)^2))

*> ncl 8> print(Z)
*

*>
*

*>
*

*> Variable: Z
*

*> Type: double
*

*> Total Size: 8 bytes
*

*> 1 values
*

*> Number of Dimensions: 1
*

*> Dimensions and sizes: [1]
*

*> Coordinates:
*

*> (0) 2.775265831051694e-09
*

*>
*

*>You need to load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
*

*>to get the function flt2dble.
*

*>
*

*>Your original problem is that some of the expressions on the right-hand
*

*>side are underflowing to zero in single precision. Notice that Z is now
*

*>a double, which could be converted back to single precision using dble2flt.
*

*>
*

*>Andy
*

*>
*

*>Dave Brown wrote:
*

*>Another way that does not require the 'flt2dble' contributed function
*

*>is to use the 'd' suffix to
*

*>make the quantities that are in danger of underflowing explicitly
*

*>double-precision:
*

*>ncl 5> Z=2*(1.3806d*10^(-23))^4/(((6.626d*10^(-34))^3)*((3*10^8)^2))
*

*>ncl 6> print(Z)
*

===

Andy's/Dave's analysis/solution are both correct.

I would likely, put a "d" after each "token"

ncl 5> X=2d*(1.3806d*10d^(-23))^4/(((6.626d*10d^(-34))^3)*((3d*10d^8)^2))

or, perhaps cleaner/shorter

ncl 6> Y=2d*(1.3806d*1d-23)^4/(((6.626d*1d-34)^3)*((3d*1d08)^2))

ncl 7> YF

X = 2.775266336532462e-09 all double

Y = 2.775266336532462e-09

Z = 2.775265831051694e-09 some double

YF = 2.775266e-09 = doubletofloat( Y )

ZF = 2.775266e-09 = doubletofloat( Z )

_______________________________________________

ncl-talk mailing list

ncl-talk_at_ucar.edu

http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Fri Nov 10 2006 - 14:36:33 MST

*
This archive was generated by hypermail 2.2.0
: Fri Nov 10 2006 - 14:39:27 MST
*