2

When representing latitude and longitude in degrees, minutes and seconds, with

  • -180 <= D <= 180 (or -90 and 90)
  • 0 <= M < 60 (0 if D is at an extreme)
  • 0 <= S < 60 (0 if D is at an extreme)

How can values between -1 degree and 0 degrees be represented? Since there is no distinction between 0 and -0, there is no way to distinguish between 0:12:34 and -0:12:34.

Is this just a limitation of this kind of representation, or is there some convention that allows it to cover this gap?

yoozer8
  • 123
  • 4

1 Answers1

2

I assume you're talking programatically, in which case I would store angles in decimal degrees, and have a function that pretty-prints DMS on demand. It can get a little hairy with rounding, but nothing insurmountable.

If you want to store an angle in DMS form, then you'll need a hemisphere flag to cope with your corner case. You remove the rounding issue, but you do then introduce complexity when comparing and adding angles - nothing a sprinkling of operator overloads won't fix however.

MerseyViking
  • 14,543
  • 1
  • 41
  • 75
  • We are storing angles in decimal degrees, but need to provide the Degrees Minutes and Seconds values on demand, individually (there could be a request for only the minutes of a particular latitude). – yoozer8 Oct 03 '12 at 15:59
  • (+1) The algorithm, Jim, is to convert the absolute value of DD into DMS and then just tack on the appropriate sign. If you're outputting D, M, and S as numerical values (rather than a string), then you must supply an extra bit of information, as MerseyViking says. This is conventionally done either via north-south-east-west indicators or quite literally as a sign bit. – whuber Oct 03 '12 at 16:50