[ncl-talk] commands to handle exponential calculation to return E100 instead of infinity
Rick Brownrigg
brownrig at ucar.edu
Wed Apr 26 22:08:21 MDT 2017
Hi Yi-Chih,
I am not sure what you mean by "...But b12^log(L(j,k))d in the do loop is
not working...".
But hopefully to clarify, NCL is a typed language, so that:
1 ; is an integer
1. ; is a float
1d ; is a double
1.d ; is a double
and in general, unless the documentation states otherwise, many functions
in NCL are integer-in/integer-out, float-in/float-out, etc.
So if in your example, "L(j,k)" is a float value, "log(L(j,k))" will be a
float value, and subject to the valid range of floats. Going back to your
original example:
b10 = todouble(exp(230.84))
230.84 is a float value, and exp(230.84) will be a float value that happens
to exceed the valid range of floats. To coerce the result to double, you'll
want:
b10 = exp(todouble(230.84)) ;; which is equivalent to "exp(230.84d)"
Hope that helps...
Rick
On Wed, Apr 26, 2017 at 8:27 PM, Yi-Chih Huang <dscpln at gmail.com> wrote:
> Hello,
>
> The exp(230.84d) is working. But b12^log(L(j,k))d in the do loop is
> not working. What would be the command to handle extreme large or extreme
> small numbers in do loop?
>
> Thanks,
>
> Yi-Chih
>
>
> On Thu, Apr 27, 2017 at 1:34 AM, Rick Brownrigg <brownrig at ucar.edu> wrote:
>
>> This yields a float result, which is out of range for floats:
>>
>> b10 = exp(230.84)
>> b20 = exp(203.22)
>>
>> Try explicitly making the constants double:
>>
>> b10 = exp(230.84d)
>> b20 = exp(203.22d)
>>
>>
>> On Wed, Apr 26, 2017 at 5:27 AM, Yi-Chih Huang <dscpln at gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I work on NCL Version 6.1.2. It said the range of double type is
>>> e-308 - e+307 on https://www.ncl.ucar.edu/Do
>>> cument/Manuals/Ref_Manual/NclDataTypes.shtml. Although I have tried
>>> several ways, I only got infinity and 8 bits in return. Could you show me
>>> the command to handle exponential calculation
>>>
>>>
>>> b10 = todouble(exp(230.84))
>>> b20 = todouble(exp(203.22))
>>> b30 = new(1,double,0)
>>> print(b10+" "+b20+" "+b30)
>>>
>>> Variable: b30
>>> Type: double
>>> Total Size: 8 bytes
>>> 1 values
>>> Number of Dimensions: 1
>>> Dimensions and sizes: [1]
>>> Coordinates:
>>>
>>> (0) inf inf inf
>>>
>>> $ ncl -v
>>> Unknown option `-v'
>>> Copyright (C) 1995-2013 - All Rights Reserved
>>> University Corporation for Atmospheric Research
>>> NCAR Command Language Version 6.1.2
>>> The use of this software is governed by a License Agreement.
>>> See http://www.ncl.ucar.edu/ for more details.
>>>
>>> Thanks much,
>>>
>>> Yi-Chih
>>>
>>> _______________________________________________
>>> 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/20170426/838f07f5/attachment.html
More information about the ncl-talk
mailing list