Home > Archive > APL > July 2004 > Re: Integer or Floating Point? Now with calendar code (and one last
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Integer or Floating Point? Now with calendar code (and one last
|
|
| Jerry Koniecki 2004-07-12, 3:57 pm |
| rkarcher@frey.de wrote:
>
> Jerry Koniecki <NOspam@my.mailbox> wrote:
> Try {first} or 1 {pick}
The clumsy "{execute}{format}" seems to work. But so does your
suggestion,
which I like better. And here is the code which only fails on a special
case.
C <- CALENDAR YM;days;DIM;FD;LS;M;R;TS;Y
[1] {lamp} generate monthly calendar
[2] (Y M) <- YM {lamp} year, month
[3] FD <- {pick} WEEKDAY M 1 Y {lamp} first day of month; WEEKDAY from
Jacob Brickman's JBUTIL available at Waterloo archives
[4] DIM <- 31 28 31 30 31 30 31 31 30 31 30 31 {lamp} days in month
[5] :If {~=}/0=4 100 400 4000 | Y {diamond} DIM[2] <- 29 {diamond}
:Endif {lamp} leap year correction; adapted from Jacob Brickman's CAL
function
[6] days <- 'Su Mo Tu We Th Fr Sa '
[7] LS <- FD-1 {diamond} TS <- 7 | 7-7 | DIM[M]-7-FD-1 {lamp} leading &
trailing spaces
[8] R <- (LS+TS+DIM[M]) {divide} 7 {lamp} rows in calendar
[9] C <- ((4{rho}' '),{quad}M[M;],' ',({format}Y),3{rho}'
'){catbar}days{catbar}{format}R 7{rho}((LS{rho}'
'),({iota}DIM[M]),TS{rho}' ') {lamp} build month
This works fine, EXCEPT in ONE special case; a 'perfect month'. i.e. a
non-leap year
February which starts on Sunday (e.g. 1998 2). Line 9 fails with a
LENGTH ERROR at
days. Days is not at fault, but rather the rest of the line which builds
a 4 by 20
array, instead of a 4 by 21 array; but only for a 'perfect month'.
Anyone see how
to fix this?
--
Jerry wa2rkn no email @ present
| |
| Ted Edwards 2004-07-12, 3:57 pm |
| Jerry Koniecki wrote:
> days. Days is not at fault, but rather the rest of the line which builds
> a 4 by 20
> array, instead of a 4 by 21 array; but only for a 'perfect month'.
> Anyone see how
> to fix this?
I already told you. Use {floor}0.5+... to get your integer. Your
division is likely coming out to 20.99999999 instead of 21.
Ted
| |
| Jerry Koniecki 2004-07-14, 8:55 am |
| Ted Edwards wrote:
>
> Jerry Koniecki wrote:
>
>
> I already told you. Use {floor}0.5+... to get your integer. Your
> division is likely coming out to 20.99999999 instead of 21.
Yes, you did, but you are wrong. The floating point has been changed to
an
integer scalar in line [3] by {pick} WEEKDAY from where it had been
propagating
and causing a problem. And the {divide} in line [8] assigns an integer
scalar
to R. And just to forstall another round of 'use {floor}0.5+...', I
verified
it is irrelevant.
Strangely, I wrote adifferent function to accomplish the same thing,
but
it fails exactly the same. Instead of only 9 lines though, it is 14, so
I
prefer to fix the posted function.
--
Jerry wa2rkn no email @ present
| |
| Jerry Koniecki 2004-07-18, 8:55 am |
| Reinhard Karcher wrote:
>
> Jerry Koniecki <NOspam@my.mailbox> wrote:
> [ snip ]
>
> On APL2 (DOS) I always get a 4 by 20 array.
4 by 20 on other than "perfect months"? So the function works for you in
all cases
if you:
trim the trailing space in 'days' in line [6]
change line [9] from ((4{rho}' ')... to ((3{rho}' ')...
?
--
Jerry wa2rkn no email @ present
| |
| Jerry Koniecki 2004-07-26, 8:55 am |
| Jerry Koniecki wrote:
> which I like better. And here is the code which only fails on a special
> case.
>
> C <- CALENDAR YM;days;DIM;FD;LS;M;R;TS;Y
> [1] {lamp} generate monthly calendar
> [2] (Y M) <- YM {lamp} year, month
> [3] FD <- {pick} WEEKDAY M 1 Y {lamp} first day of month; WEEKDAY from
> Jacob Brickman's JBUTIL available at Waterloo archives
> [4] DIM <- 31 28 31 30 31 30 31 31 30 31 30 31 {lamp} days in month
> [5] :If {~=}/0=4 100 400 4000 | Y {diamond} DIM[2] <- 29 {diamond}
> :Endif {lamp} leap year correction; adapted from Jacob Brickman's CAL
> function
> [6] days <- 'Su Mo Tu We Th Fr Sa '
> [7] LS <- FD-1 {diamond} TS <- 7 | 7-7 | DIM[M]-7-FD-1 {lamp} leading &
> trailing spaces
> [8] R <- (LS+TS+DIM[M]) {divide} 7 {lamp} rows in calendar
> [9] C <- ((4{rho}' '),{quad}M[M;],' ',({format}Y),3{rho}'
> '){catbar}days{catbar}{format}R 7{rho}((LS{rho}'
> '),({iota}DIM[M]),TS{rho}' ') {lamp} build month
>
> This works fine, EXCEPT in ONE special case; a 'perfect month'. i.e. a
> non-leap year
> February which starts on Sunday (e.g. 1998 2). Line 9 fails with a
> LENGTH ERROR at
> days. Days is not at fault, but rather the rest of the line which builds
> a 4 by 20
> array, instead of a 4 by 21 array; but only for a 'perfect month'.
> Anyone see how
> to fix this?
Seems the problem was related to {quad}CS (compatibility setting) in
APLX. If set to 4
instead of the default 0, the function works; although it does shift the
'perfect month'
date array one space to the right. The problem is now one of 'pretty
printing' rather
than a failing function. So I rewrote the function to also work under
flat APL
(APL.68000 Level I), and all works now as I expect it to ('perfect
month' date array
no longer shifts one space). Thanks to all who responded with helpful
sugestions.
The newsgroup seemed a little more lively. Looking forward to the next
interesting
topic. In the unlikely event anyone wants the final function, I'm
willing to post
or email it.
N2BA : I thought I was the only one here. 73
--
Jerry wa2rkn no email @ present
|
|
|
|
|