This is no different from any decimal ...

But if I have the decimal number -345, this is
    -(3*10^2 + 4*10^1 + 5*10^0)
or
    -1 * (3*10^2 + 4*10^1 + 5*10^0)
or
    -3*10^2 + -4*10^1 + -5*10^0
or
    -3*10^2 - 4*10^1 - 5*10^0
and not
    -3*10^2 + 4*10^1 + 5*10^0
and similarly for numbers represented in sexagesimal base.

Negative numbers are only permitted in the degree column.

Unfortunately, if one has a d/m/s tuple  @dms = (3, 4, 5) one cannot negate it by writing -@dms. One has to negate each element:
    @neg_dms = map -1*$_, @dms;
or (-3, -4, -5). IIUC, the notation -3° 4' 5" is equivalent to the tuple (-3°, -4', -5") analogously to decimal notation. Klaf is describing and giving an example of base-60 subtraction with borrowing, but that is not fundamentally different from base-10 subtraction.

Update 1: Added the "Negative numbers ..." quote before the second paragraph for clarification, and various other minor wording changes and additions.

Update 2: Here's the Klaf subtraction example in terms of normalizing everything to decimal arc-seconds, doing a decimal subtraction and reducing arc-seconds to a d/m/s tuple:

c:\@Work\Perl\monks\thechartist>perl -wMstrict -le "sub dms_2_secs { my ($degs, $mins, $secs) = @_; ;; return $degs * 3600 + $mins * 60 + $secs; } ;; sub secs_2_dms { use integer; ;; my ($secs) = @_; ;; my $degs = $secs / 3600; $secs %= 3600; my $mins = $secs / 60; $secs %= 60; ;; return $degs, $mins, $secs; } ;; my $klaf_arc_secs = dms_2_secs(83, 18, 21) - dms_2_secs(39, 41, 28); my @klaf_dms = secs_2_dms($klaf_arc_secs); print qq{(@klaf_dms)}; " (43 36 53)
(Update: The Klaf addition example also works correctly.) (Update: Moreover, the reversed subtraction  dms_2_secs(39, 41, 28) - dms_2_secs(83, 18, 21) yields the expected (-43 -36 -53) tuple.)


Give a man a fish:  <%-{-{-{-<


In reply to Re^7: How to write testable command line script? (updated) by AnomalousMonk
in thread How to write testable command line script? by thechartist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.