The Museum of HP Calculators

HP Forum Archive 18

[ Return to Index | Top of Index ]

Formulas for ->HMS & ->HR
Message #1 Posted by Pekis on 8 June 2008, 5:48 p.m.


... 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 ! Ex: ->HR(1.2)=1.33333333333 (i.e. 4/3) but ->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.

[ Return to Index | Top of Index ]

Go back to the main exhibit hall