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 
Return to the default flat view Create a new topic Submit Reply
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 previous 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...
[Message index]
 
Read Message
Read Message
Read Message
Read Message
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:57:11 PDT 2025

Total time taken to generate the page: 0.00349 seconds