Post Reply 
(11C) (15C) days per month (without labels or registers)
04-07-2018, 12:50 PM
Post: #1
(11C) (15C) days per month (without labels or registers)
I ran out of labels and registers so here is a way to calculate the number of days per month using only one flag. Note that it always returns 28 days for February, so it's 98% accurate ;)

Code:
CF 0
2
x><y
TEST x = y
  SF 0
.
8
8
/
INT
2
GSB "modulo" ; you need a modulo function somewhere
3
0
+
F? 0
  -
ABS
RTN

As you can see you need a modulo function. If you don't already have one in your calculator you can use this one:

Code:
LBL "modulo"
X<>Y
STO .7
X<>Y
/
LastX
X<>Y
INT
x
RCL .7
X<>Y

RTN
Find all posts by this user
Quote this message in a reply
04-08-2018, 08:33 AM (This post was last modified: 04-08-2018 08:45 AM by Dieter.)
Post: #2
RE: (11C) (15C) days per month (without labels or registers)
(04-07-2018 12:50 PM)michaelzinn Wrote:  I ran out of labels and registers so here is a way to calculate the number of days per month using only one flag. Note that it always returns 28 days for February, so it's 98% accurate Wink

That's a nice idea: dividing by 0,88 adds 1 to the integer part of a month ≥ 8.
But there is no need for a special mod routine: since only x mod 2 is calculated you can do it with a simple 2 / FRAC 2 *.

Here is another method that uses only integer arithmetics so that it can be used on systems without floating point support:

days = ((m + m shr 3) and 1) + 30

The shift right operation divides by 8 and leaves the integer part (0 or 1), and the AND operator returns 0 for even and 1 for odd numbers.
Maybe someone can implement this on a 16C.

Yes, the February case has to be handled separately. ;-)

A few more thoughts on this – with more or less practical benefit – can be found here. Including the February case and leap year detection.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)