
sub Frac(Real \x --> Real) is export(:apc-math) {
sub Modulo(Real \x, Real \y --> Real) is export(:apc-math) {
sub Ddd(Int \D, Int \M, Real \S, :$debug --> Real) is export(:Ddd) {
sub DMS(Real \Dd, Int $D is rw, Int $M is rw, Real $S is rw) is export(:DMS) {
enum AngleFormat is export(:apc-position) ( 
    Dd      => 1, # decimal repr
    DMM     => 2, # deg and whole min of arc
    DMMm    => 3, # deg and min of arc in decimal repr
    DMMSS   => 4, # deg, min of arc and whole sec of arc
    DDMMSSs => 5, # deg, min, sec of arc in decimal repr
);
sub Angle(Real $angle, AngleFormat = Dd) is export(:apc-position) {
}
class Angle is export(:apc-position) {
    has Real $.angle;
    has AngleFormat $.Format = Dd;

sub mjd2jd($mjd) is export(:apc-time) {
sub jd2mjd($jd) is export(:apc-time) {
sub Mjd(Int $Year is copy, Int $Month is copy, Int \Day,
        Int \Hour = 0, Int \Min = 0, Real \Sec = 0.0 
        --> Real) is export(:apc-time) {
multi sub CalDat(
    Real \Mjd,
    Int $Year is rw, Int $Month is rw, Int $Day is rw, Real $Hour is rw
    ) is export(:apc-time) {
multi sub CalDat(
    Real \Mjd,
    Int $Year is rw, Int $Month is rw, Int $Day is rw, 
    Int $Hour is rw, Int $Min is rw, Real $Sec is rw
    ) is export(:apc-time) {
enum TimeFormat is export(:apc-time) (
    None   => 1, # no time, date only
    DDd    => 2, # output time as fraction of a day
    HHh    => 3, # output time as hours with one decimal place
    HHMM   => 4, # output time as hours and minutes (rounded to the next minute)
    HHMMSS => 5, # output time as hours, min, sec (rounded to next sec)
);
sub Time(Real $hour, TimeFormat = HHMMSS) is export(:apc-time) {
class Time is export(:apc-time) {
    has Real $.Hour;
    has TimeFormat $.Format = HHMMSS;
    method new(Real $Hour, TimeFormat $Format = HHMMSS) {
                'HHMM'
sub Datetime(Real $Mjd, TimeFormat = None) is export(:apc-time) {
class Datetime is export(:apc-time) {
    has Real $.Mjd;
    has TimeFormat $.Format = None;
