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

Home » Public Forums » archive » Identify whether value is integer in IF statement
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
Identify whether value is integer in IF statement [message #91148] Tue, 09 June 2015 06:49 Go to next message
jecca.baker is currently offline  jecca.baker
Messages: 12
Registered: October 2014
Junior Member
I'm trying to automate identification of leap years.

I was thinking something like:

FOR YR=0, 10-1 DO BEGIN
YEAR=2001+YR
IF (YEAR/4) EQ ?an integer? THEN BEGIN
*
*
*
ENDIF
ENDFOR

How do I identify whether YEAR/4 is an integer (ie a leap year)?

Thanks.
Re: Identify whether value is integer in IF statement [message #91149 is a reply to message #91148] Tue, 09 June 2015 06:56 Go to previous messageGo to next message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Tue, 9 Jun 2015 06:49:25 -0700 (PDT), Jess wrote:

> How do I identify whether YEAR/4 is an integer (ie a leap year)?
>
if year mod 4 eq 0 then begin
Re: Identify whether value is integer in IF statement [message #91150 is a reply to message #91148] Tue, 09 June 2015 07:05 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Tuesday, June 9, 2015 at 3:49:27 PM UTC+2, Jess wrote:
> I'm trying to automate identification of leap years.
>
> I was thinking something like:
>
> FOR YR=0, 10-1 DO BEGIN
> YEAR=2001+YR
> IF (YEAR/4) EQ ?an integer? THEN BEGIN
> *
> *
> *
> ENDIF
> ENDFOR
>
> How do I identify whether YEAR/4 is an integer (ie a leap year)?
>
> Thanks.

One way would be to use the isa() function with the /integer keyword. But...
when you calculate year/4 you will always get an integer because an integer divided by an integer is still an integer:

IDL> for yr=0,9 do help, (2001+yr)/4
<Expression> INT = 500
<Expression> INT = 500
<Expression> INT = 500
<Expression> INT = 501
<Expression> INT = 501
<Expression> INT = 501
<Expression> INT = 501
<Expression> INT = 502
<Expression> INT = 502
<Expression> INT = 502

What you really want is probably is to check if 4 is a divisor of year. To check for this condition, you can use the "mod" operator (see http://www.exelisvis.com/docs/Mathematical_Operators.html).
Then you can check with
if (YEAR mod 4) eq 0 then ...

Cheers,
Helder

PS: Ups, too late, Heinz was faster...
Re: Identify whether value is integer in IF statement [message #91151 is a reply to message #91150] Tue, 09 June 2015 07:18 Go to previous message
jecca.baker is currently offline  jecca.baker
Messages: 12
Registered: October 2014
Junior Member
Great, thanks both of you! :-)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: set all elements in 2d array between some range to 1
Next Topic: Bug or desired behavior in lambda functions?

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

Current Time: Wed Oct 08 13:37:19 PDT 2025

Total time taken to generate the page: 0.00562 seconds