Shop OBEX P1 Docs P2 Docs Learn Events
Suggestion: Sexagesimal notation in Spin/PASM — Parallax Forums

Suggestion: Sexagesimal notation in Spin/PASM

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2020-01-20 19:56 in Propeller 1
It would be handy to allow sexagesimal (base 60, e.g. deg:min:sec, hr:min:sec, etc.) notation in Spin programs. Simply put, a number like

2:30:30 (2 hrs, 30 min., 30 sec)

would evaluate to 9030 (the number of seconds). IOW it evaluates to the units of whatever the last block represents. You could have as few or many blocks as you want, viz:

2:30 == 150 (minutes, or whatever units the 30 represents)

It would work with floating point, too:

-135:48:43.78 (i.e. 135°48'43.78"W) == -((135 * 60 + 48) * 60 + 43.78) == -488_923.78

It would come in handy when dealing with time, e.g.

next_clock_minute := (next_clock_minute + 2:30) // 24:00

IOW, you don't have to do the math in your head or with a calculator.

Use of the colon in this way would not conflict with its other use in the obj section, so its meaning is unambiguous and could easily be implemented in the compiler.

-Phil

Comments

  • IEC61131-3 has this covered a different way. Variable types like TIME (T), TIME_OF_DAY (TOD) , and DATE_AND_TIME (DT).

    MyTime : = T#11d_12h_15m_32s_299ms;
    Converts to a 32 bit number in milliseconds.

    MyDate : = TOD#2:30:30;
  • whicker wrote:
    IEC61131-3 has this covered a different way. Variable types like TIME (T), TIME_OF_DAY (TOD) , and DATE_AND_TIME (DT).
    But Spin is untyped, so I think my suggestion makes more sense.

    -Phil
Sign In or Register to comment.