Friday, June 23, 2017

HP Prime and Casio fx-CG 50: Phase of the Moon, C++ Translations to Calculator

HP Prime and Casio fx-CG 50: Phase of the Moon, C++ Translations to Calculator 

Moon Phase Program 

The following program calculates the approximate phase of the moon.  Calculation is based on the following:

1.  A base date of August 11, 1999 is used, which was a New Moon.
2.  The phases of the moon cycles approximately 29.530588853 days

The results is a phase indicator from 0 to 1. 

If the indicator is close to 0 or 1, we have a New Moon.
If the indicator above 0 but below 0.5, it’s the Waxing Crescent Moon.
If the indicator is about or exactly 0.5, we have a Full Moon.
Finally, for an indicator from 0.5 to 1, it’s the Waning Crescent Moon.

June 23, 2017:  the indicator is 0.991190947
June 24, 2017:  the indicator is 0.025054136

Values are approximate.

HP Prime Program:  MOONPHASE

Input:  MOONPHASE(yyyy.mmdd)

// Moon phase
// 0,1: New; 0.5: Full
LOCAL t,p;

Casio Program:  MOONPHSE

"EWS 2017-06-23"
Frac (T/29.530588853)->P

Locate 1,1,"PHASE %:"
Locate 1,2,"0,1: NEW,0.5: FULL"
Locate 1,3,P

Source:  “Moon Phase”  voidware.

Bonus:  From C to Calculator

The program presented on the source is written in C (C++?).  Translating from C to calculator language took a little research (confession: I’m not a C expert). 

var++  increment variable by 1.  (var + 1 → var)
var--  decrement variable by 1.  (var – 1 → var)
+=  storage addition (STO+,  var + value → var)
-=   storage subtraction (STO-, var – value → var)
*=  storage multiplication (STO*, var * value → var)
/=  storage division  (STO/,  var/value → var)
&   and
||  or
%  mod
‘! not

Source:  “C – Operators” Tutorials Point  - Simple Easy Learning  Retrieved June 23, 2017


This blog is property of Edward Shore, 2017

No comments:

Post a Comment

HP Prime: Advanced Payments for a Lease

HP Prime:   Advanced Payments for a Lease Introduction The program ADVPMT calculates the monthly payment of lease several payment...