in reply to Re^6: How to write testable command line script?
in thread How to write testable command line script?
update: AnomalousMonk said it way better than I did. Original left for historical purposes.
You've misunderstood. I am claiming you are representing negative angles incorrectly. After the subtraction, if you get -60 seconds, you should have the equivalent of -1min. -1min is represented canonically as -0° 1' 0", not as -1° 59' 0". The answer you list in Re^2: How to write testable command line script? of my $test_7 = [ 0, 0, -60]; my $answer_7 = [-1, 59, 0]; is wrong. Honestly, your format doesn't allow you to use the right answer, unless you know how to get perl to store the "-0" correctly (for example, using text), because it should be my $answer_7 = [-0, 1, 0];.
regarding normal base-10 subtraction, when you subtract 0.1 from 0.0, you do NOT borrow one from the ones column, making it -1; then have 10 in the tenths column, and subtract 1, leaving 9/10ths, or -1.9. 0.0-0.1 is obviously -0.1. What you are claiming in DMS is exactly equivalent to claiming that -60sec is -1° 59' 0".
0.0 Try borrowing: (0-1=-1).(0+10=10) => (-1).(10) -0.1 -( 0).( 1) ==== ========== -0.1 (-1).( 9) => -1.9 That's nonsensical, so obviously not the right method for subtracting a bigger from a smaller. To subtract a bigger number (M) from a smaller number (S) to do a difference D=M-S, you have to do -(S-M)=D So start with the S-M: 0.1 -0.0 ==== 0.1 Then negate the answer -0.1 The same is true in other bases, like the base 60 of DMS: 0°00'00" -0°00'60" ======== ??°??'??" You start by making the bigger the first, 0°00'60" -0°00'00" ======== ???????? Then simplify the top term and subtract 0°01'00" -0°00'00" ======== 0°01'00" The negate: -0°1'0"
However you calculate it, whether you do it in decimal degrees, or in DMS, the only difference between -60s and +60s should be the sign at the beginning. +60s is (0° 1' 0"), and -60s is -(0° 1' 0"), which gets simplified to -0° 1' 0", exactly like -(0.016) gets simplified to -0.016 -- the negative sign is placed next to the most significant digit, but implies the whole result is negative. -0.016deg converts to -(0.016deg + 0/60 + 0/3600) = -(0 + 1/60 + 0/3600) = -(0° 1' 0"). You do not interpret -0.016 = (-0) + (0/10) + (1/100) + (6/1000) -- because that math evaluates to +16/1000, which is wrong. You evaluate -0.016 as -(0.016) = -(0 + 0/10 + 1/100 + 6/1000) = -(16/1000), which is right; or, in the other direction (-16 thousandths) = -(16 thousandths) = -(1 hundredth + 6 thousandths) = -(zero ones + 0 tenths + 1 hundredths + 6 thousandths). In the same way, -60sec = -(60sec) = -(0 + 0/60 + 60/3600) = -(0 + 1/60 + 0/3600) = -(0° 1' 0") = -0° 1' 0". Negative Degress minutes seconds (-x°y'z") is not (-x°) + (y') + (z") = -x + y/60 + z/3600, it is -(x° + y' + z") -(x + y/60 + z/3600).
Have I said this in a way that makes my point more clear?
the resource https://books.google.com/books?id=YRNeBAAAQBAJ&lpg=PR1&dq=Albert%20Klaf's%20Trigonometry%20Refresher&pg=PA12#v=onepage&q&f=false did not show an example when the result is negative. I do not believe you are extending into negative results correctly.
(and linking works just fine to me: click on the LINK icon once you've navigated to the google books page, copy the URL, and paste it here between square brackets, like [https://books.google.com/books?id=YRNeBAAAQBAJ&lpg=PR1&dq=Albert%20Klaf's%20Trigonometry%20Refresher&pg=PA12#v=onepage&q&f=false].
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: How to write testable command line script?
by thechartist (Monk) on Nov 27, 2018 at 04:43 UTC | |
by pryrt (Abbot) on Nov 27, 2018 at 14:27 UTC | |
|
Re^8: How to write testable command line script?
by thechartist (Monk) on Nov 26, 2018 at 17:51 UTC | |
by pryrt (Abbot) on Nov 26, 2018 at 18:41 UTC |