Re: Problem with variable declaration [message #70518] |
Wed, 21 April 2010 10:55  |
bala murugan
Messages: 23 Registered: April 2010
|
Junior Member |
|
|
On Apr 21, 11:53 am, bala murugan <bala2...@gmail.com> wrote:
> On Apr 21, 11:47 am, pp <pp.pente...@gmail.com> wrote:
>
>> On Apr 21, 2:33 pm, bcb <bbow...@bigelow.org> wrote:
>
>>> For what it's worth, when I run this on windows using 7.1.1, I get the
>>> expected answer...
>
>> Then you must have compile_opt defint32 (or idl2) set somewhere. With
>> ints, 10^5 overflows, as jeanh pointed out.
>
> I am new to IDL. Can you please tell me how to declare a variable as
> double or float.?
I got it guys,
u=double(u)
|
|
|
|
|
Re: Problem with variable declaration [message #70521 is a reply to message #70520] |
Wed, 21 April 2010 10:36   |
bala murugan
Messages: 23 Registered: April 2010
|
Junior Member |
|
|
On Apr 21, 11:31 am, jeanh
<jghasb...@DELETETHIS.environmentalmodelers.ANDTHIS.com> wrote:
> On 21/04/2010 1:24 PM, bala murugan wrote:
>
>> Hi guys,
>
>> IDL> print,((10^5)/(exp(10)*factorial(5)))
>
>> The actual result of the above line is 0.0378332748
>
>> But when we run it in IDL we get the result as -0.011755556
>
>> What should be done to rectify this?
>
>> Thanks,
>> B
>
> be careful of your data type.
> 10^5 will not work, as the result is an integer... but its intended
> value is too big for an integer!
>
> IDL> help,(10^5)
> <Expression> INT = -31072
>
> So you can compute this with double precision
>
> IDL> help,(10D^5)
> <Expression> DOUBLE = 100000.00
>
> IDL> print,((10^5)/(exp(10)*factorial(5)))
> -0.011755555
> IDL> print,((10D^5)/(exp(10)*factorial(5)))
> 0.037833276
>
> Jean
Thanks a lot Jean. But when I use an expression like the following,
a = (u^x)/(exp(u)*factorial(x))
where u=10 & x=5,
What should I do in this case?
|
|
|
Re: Problem with variable declaration [message #70522 is a reply to message #70521] |
Wed, 21 April 2010 10:34   |
bala murugan
Messages: 23 Registered: April 2010
|
Junior Member |
|
|
On Apr 21, 11:31 am, jeanh
<jghasb...@DELETETHIS.environmentalmodelers.ANDTHIS.com> wrote:
> On 21/04/2010 1:24 PM, bala murugan wrote:
>
>> Hi guys,
>
>> IDL> print,((10^5)/(exp(10)*factorial(5)))
>
>> The actual result of the above line is 0.0378332748
>
>> But when we run it in IDL we get the result as -0.011755556
>
>> What should be done to rectify this?
>
>> Thanks,
>> B
>
> be careful of your data type.
> 10^5 will not work, as the result is an integer... but its intended
> value is too big for an integer!
>
> IDL> help,(10^5)
> <Expression> INT = -31072
>
> So you can compute this with double precision
>
> IDL> help,(10D^5)
> <Expression> DOUBLE = 100000.00
>
> IDL> print,((10^5)/(exp(10)*factorial(5)))
> -0.011755555
> IDL> print,((10D^5)/(exp(10)*factorial(5)))
> 0.037833276
>
> Jean
Thanks a lot Jean. But when I am using an expression like the
following,
a = (u^x)/(exp(u)*factorial(x))
where u=10 & x = 5
What do I do in this case?
|
|
|
|
Re: Problem with variable declaration [message #70524 is a reply to message #70523] |
Wed, 21 April 2010 10:31   |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
On 21/04/2010 1:24 PM, bala murugan wrote:
> Hi guys,
>
> IDL> print,((10^5)/(exp(10)*factorial(5)))
>
> The actual result of the above line is 0.0378332748
>
> But when we run it in IDL we get the result as -0.011755556
>
> What should be done to rectify this?
>
> Thanks,
> B
be careful of your data type.
10^5 will not work, as the result is an integer... but its intended
value is too big for an integer!
IDL> help,(10^5)
<Expression> INT = -31072
So you can compute this with double precision
IDL> help,(10D^5)
<Expression> DOUBLE = 100000.00
IDL> print,((10^5)/(exp(10)*factorial(5)))
-0.011755555
IDL> print,((10D^5)/(exp(10)*factorial(5)))
0.037833276
Jean
|
|
|
Re: Problem with variable declaration [message #70617 is a reply to message #70518] |
Wed, 21 April 2010 10:59  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Apr 21, 2:55 pm, bala murugan <bala2...@gmail.com> wrote:
>> I am new to IDL. Can you please tell me how to declare a variable as
>> double or float.?
>
> I got it guys,
>
> u=double(u)
That is a conversion, not a declaration. In the case you mentioned
above, you can declare as
u=10d0 & x=5d0
|
|
|