HP Forums
Formulas for ->HMS & ->HR - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Formulas for ->HMS & ->HR (/thread-137892.html)

Formulas for ->HMS & ->HR - Pekis - 06-08-2008


... A bit of fun with maths ... :)
One day I've discovered these formulas from my personal work:

Decimal number -> Hours, minutes and seconds

->HMS(x): (90*x+100*INT(x)+INT(60*x))/250

Ex: ->HMS(pi)=3.08297335529 (i.e. 3 h 08 m 29.73... s)

Hours, minutes and seconds -> decimal number

->HR(x): (250*x-60*INT(x)-INT(100*x))/90

Ex: ->HR(3.08297335529)=3.14159265359

Are these formulas well known ?

Rem.: Beware of internal representation of some numbers !
->HR(1.2)=1.33333333333 (i.e. 4/3)
->HMS(4/3) must be 1.2, and not 1.196 due to the fact that 60*1.33333333333=79.9999999998, so INT(79.9999999998)=79, even if 79.9999999998 was displayed as 80.0000 in FIX 4 !
Solution: Always round first to a fixed number of significant digits before applying INT, so 79.9999999998 is rounded first to 80.