Am 08.05.20 um 14:30 schrieb Allin Cottrell:
On Fri, 8 May 2020, Artur Tarassow wrote:
> I've stumbled over this weird thing trying to retrieve the day of
> Easter Sunday applying the easterday() function as shown in the help
> text.
>
> However, it seems that scalar "d" is not a proper integer as trying
> to restrict the sample to a single day fails with the error message
> "No observations would be left!". Replacing "d" in the
"smpl" command
> by 5 works though. This is using latest git on Ubuntu 19.10.
>
> <hansl>
> clear
> set verbose off
> nulldata 200
> setobs 7 2015-01-01 --time-series
>
> series year, month, day
> isoconv($obsdate, &year, &month, &day)
>
> scalar e = easterday(2015)
> scalar m = floor(e)
> scalar d = 100*(e-m)
[...]
Adding at this point
printf "4.05 = %.15f\n", 4.05
printf "d = %.15f\n", d
eval d == 5
reveals
4.05 = 4.050000000000001
d = 4.999999999999983
0
So round() will take d to 5, but not floor(). Hansl doesn't do integer
arithmetic -- and couldn't in this case anyway since e = 4.05, coding
for the 5th of April.
It seems to me easterday() would be better returning a 2-vector
holding month and day. As things stand you have to use round() on the
day, or take this approach:
edate = sprintf("%.2f", easterday(2015))
scalar m, d
sscanf(edate, "%d.%d", m, d)
eval d == 5 # gives 1
Thanks for your alternative approach, Allin. Do you think your
suggestion is more reliable compared to the application of round() in
this case, or are there some edge-cases where round() may fail here?
I've tried round() here for a several years and it seems to work properly.
Artur