comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Problem with variable declaration
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Problem with variable declaration [message #70518] Wed, 21 April 2010 10:55 Go to next message
bala murugan is currently offline  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 #70519 is a reply to message #70518] Wed, 21 April 2010 10:53 Go to previous messageGo to next message
bala murugan is currently offline  bala murugan
Messages: 23
Registered: April 2010
Junior Member
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.?
Re: Problem with variable declaration [message #70520 is a reply to message #70519] Wed, 21 April 2010 10:47 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
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.
Re: Problem with variable declaration [message #70521 is a reply to message #70520] Wed, 21 April 2010 10:36 Go to previous messageGo to next message
bala murugan is currently offline  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 Go to previous messageGo to next message
bala murugan is currently offline  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 #70523 is a reply to message #70522] Wed, 21 April 2010 10:33 Go to previous messageGo to next message
Bruce Bowler is currently offline  Bruce Bowler
Messages: 128
Registered: September 1998
Senior Member
On Wed, 21 Apr 2010 10:24:29 -0700, 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

For what it's worth, when I run this on windows using 7.1.1, I get the
expected answer...

Are you sure you haven't redefined exp or factorial?

B
Re: Problem with variable declaration [message #70524 is a reply to message #70523] Wed, 21 April 2010 10:31 Go to previous messageGo to next message
jeanh is currently offline  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 Go to previous message
penteado is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Arc of a circle
Next Topic: Problem with variable declaration

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:43:25 PDT 2025

Total time taken to generate the page: 0.00688 seconds