(11C) (15C) days per month (without labels or registers)

04072018, 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 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" 

04082018, 08:33 AM
(This post was last modified: 04082018 08:45 AM by Dieter.)
Post: #2




RE: (11C) (15C) days per month (without labels or registers)
(04072018 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 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 

« Next Oldest  Next Newest »

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