Back with my DEG<->DMS formulas ! - 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: Back with my DEG<->DMS formulas ! (/thread-219773.html) |
Back with my DEG<->DMS formulas ! - PGILLET - 05-02-2012 Hello,
I thought it could interest you to know how I got these formulas (with x>0):
DEG->DMS(x)=(90*x+INT(60*x)+100*INT(x))/250
To compute DEG->DMS(x):
D = unknown degrees as integer
Known x=D+M/60+s/3600
D = INT(x)
M = INT(60*x-60*D)
s = 3600*x-3600*D-60*M
DMS(x) = D+M/100+s/10000
It's mathematically exact, but special care is needed in evaluating INT(60*x) on a calculator.
To compute DMS->DEG(x):
D = unknown degrees as integer
Known x=D+M/100+s/10000
D = INT(x)
M = INT(100*x-100*D)
s = 10000*x-10000*D-100*M
DEG(x) = D+M/60+s/3600
Thanks for reading ! Edited: 2 May 2012, 3:08 a.m.
Re: Back with my DEG<->DMS formulas ! - Luiz C. Vieira (Brazil) - 05-02-2012 Hi! Wow! Great work! I have written some programs just to take a DMS number and show it in DMS format, I mean, take something like 123.455959 and return the string "123º45'59"59" so it would be easier to read the DMS itself. My first two versions worked pretty well until I tried them with negative numbers. Your formulas are way more sophisticated, they are used to compute the DMS and the DEG versions of each other, I see that. But I also noticed that they seem to have no provision for negative input data; do they work accordingly in this case? I did not try any, could not tell, but since they mostly add factors, I felt as if they may deal only with positive numbers. Best regards.
Luiz (Brazil)
Re: Back with my DEG<->DMS formulas ! - PGILLET - 05-02-2012 Hello, Thanks for your answer.
Their sophistication is in their simplicity (one line formulas). Re: Back with my DEG<->DMS formulas ! - Luiz C. Vieira (Brazil) - 05-02-2012 Hi.
My bad, sorry. I read the (x>0) but my brain did not convert it into information, just the words 'x is greater than zero' echoing in the void... Gee, must give it a break. Quote:I could not say it differently. It is also the beauty of the complex solutions expressed as simple terms and expressions. Touchè! Thanks!
Luiz (Brazil) Edited: 2 May 2012, 10:31 a.m.
Re: Back with my DEG<->DMS formulas ! - Matt Agajanian - 05-02-2012 Hello there. PGILLET and the rest of the crew, I'm glad my original inquiry has sparked some inspiration. My pleasure.
Re: Back with my DEG<->DMS formulas ! - Bart (UK) - 05-03-2012 Thank you, now my 18C can do it too :-)
|