in reply to Re^6: How to write testable command line script?
in thread How to write testable command line script?
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:
(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.)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)
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: How to write testable command line script? (updated)
by thechartist (Monk) on Nov 26, 2018 at 17:47 UTC | |
by AnomalousMonk (Archbishop) on Nov 26, 2018 at 21:19 UTC | |
by thechartist (Monk) on Nov 26, 2018 at 21:53 UTC | |
|
Re^8: How to write testable command line script?
by thechartist (Monk) on Nov 26, 2018 at 16:57 UTC | |
by AnomalousMonk (Archbishop) on Nov 26, 2018 at 17:54 UTC |