Jump to content

Template talk:Deg2DMS

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Minus signs?

[edit]

Hyphens for negative values? Even if a minus sign is passed in to the template? Surely should be fixed. Lithopsian (talk) 19:42, 24 August 2020 (UTC)[reply]

Template-protected edit request on 13 November 2020

[edit]

Please change the apostrophe symbols (encoded as ') to correct (angled) ′ (′) and double-″ (″) symbols, to match e.g. Template:DEC.

More specifically, the code is changed to

<!--
-->{{#expr: FLOOR({{{1|0}}})}}° <!--
-->{{#expr: FLOOR( ((({{{1|0}}}) - FLOOR({{{1|0}}})) round 14 )*60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!--
-->{{#expr: (((({{{1|0}}})-FLOOR({{{1|0}}}))*60) - FLOOR( ((({{{1|0}}})-FLOOR({{{1|0}}})) round 14 )*60))*60 round {{#if:{{{p|}}}|{{{p|}}}|3}}}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}

Er... while you're at it, that equation for the seconds is a bit silly. It's more conveniently written as (x*60 - floor(x*60)) * 60 round 3, or in full:

<!--
-->{{#expr: FLOOR({{{1|0}}})}}° <!--
-->{{#expr: FLOOR( ((({{{1|0}}}) - FLOOR({{{1|0}}})) round 14 )*60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!--
-->{{#expr: (60*({{{1|0}}})-floor(60*({{{1|0}}}))) * 60 round {{#if:{{{p|}}}|{{{p|}}}|3}}}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}

92.119.17.10 (talk) 00:10, 14 November 2020 (UTC)[reply]

 Partly done: The first request is done. For the second, please put the code into the sandbox and create some testcases to show the difference. Thanks. – Jonesey95 (talk) 15:06, 14 November 2020 (UTC)[reply]
@Jonesey95: Thank you! For the second edit, here's an example table comparing the output of the two. (The code above is in Template:X40, and Template:X41 is a comparison helper
|-

| {{{1}}} || {{Deg2DMS|{{{1}}}|p={{{p|}}}}} || {{X40|{{{1}}}|p={{{p|}}}}}

As you can see, the replacement is equivalent, but shares certain problems with the original (see the 7th, 8th and 9th example below, as well as the last). I can come up with a replacement that fixes everything, but that's a bit more work. Now implemented in Template:X42.

Comparison of old and proposed replacements
Input Deg2DMS X40 X42

{{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}} {{X41}}

Any opinions? 92.119.17.10 (talk) 00:05, 16 November 2020 (UTC)[reply]

The working code, preserved for when Template:X42 gets erased:
{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) / 3600)}}° <!--
-->{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) mod 3600 / 60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!--
-->{{#expr: ({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) fmod 60}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}
92.119.17.10 (talk) 00:08, 16 November 2020 (UTC)[reply]

Per discussion and examples above, replace the logic with

<!--
-->{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) / 3600)}}° <!--
-->{{#expr: trunc(({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) mod 3600 / 60)}}{{#if:{{{sup|}}}|<sup>m</sup>|′}} <!--
-->{{#expr: ({{{1|0}}} * 3600 round {{#if:{{{p|}}}|{{{p|}}}|3}}) fmod 60}}{{#if:{{{sup|}}}|<sup>s</sup>|″}}

This converts the entire angle to seconds and rounds to the specified precision before breaking it apart into degrees and minutes, avoiding certain corner case bugs where the different components would be rounded in different directions, or seconds would be rounded to 60. 92.119.17.10 (talk) 03:31, 16 November 2020 (UTC)[reply]

 Done looking good. For future information, the best place to sandbox your code is the template's own sandbox, in this case Template:Deg2DMS/sandbox and testing can be done in Template:Deg2DMS/testcases — Martin (MSGJ · talk) 09:21, 18 November 2020 (UTC)[reply]
Sorry for the delay in getting to this one; I wanted to test it more thoroughly. It looks like the |p= parameter is not working properly. See Template:Deg2DMS/testcases#Precision parameter. I have put the old template code into the sandbox to show the difference. – Jonesey95 (talk) 15:06, 18 November 2020 (UTC)[reply]
@Jonesey95 and MSGJ: H'm, the new error is interesting. The problem is not with |p= proper; it's just that the value |p=4 happens to trigger a window where the fmod is revlealing some rounding in the lsbits that is causing a mess. But rounding the arc seconds before the fmod is critical to not displaying 60 seconds. How about just a "redundant" re-rounding after the fmod? I've put that in the sandbox, which seems to work. There's a comment in the wikisource because it's ugly. 64.44.80.252 (talk) 07:13, 19 November 2020 (UTC)[reply]
Seems to work, so I have copied it to the live template. I will trust other editors to point out any problems with the new code. The test cases page could use some more examples from real-world use in articles. – Jonesey95 (talk) 17:28, 19 November 2020 (UTC)[reply]