0

I am trying to build a custom format specified for doubles for a two line element (tle) for space objects. From the wiki documentation TLEs

Where decimal points are assumed, they are leading decimal points. The last two symbols in Fields 10 and 11 of the first line give powers of 10 to apply to the preceding decimal. Thus, for example, Field 11 (-11606-4) translates to −0.11606E−4 (−0.11606×10−4).

This field is 8 characters long. First character is +/-/' ' followed by 5 numeric values (No zero padding) followed by a '-' and a single exponent value.

Does anyone know how to build this inline? ie $"{val,someFormat}" This would be preferred however I don't think it is possible so the alternative would be composing it of several pieces like

$"{val<0?"-":" "}{frac(val)}-{getExp(val)}".

Both frac() and getExp() need to be built, but my biggest problem is how to get the exponential value of the double. Is there any built in function that will return an int value of the exponent of a double? With that I think I can build everything else.

Again if there is an easier way I am all ears! Thanks

vbbartlett
  • 179
  • 2
  • 14
  • Does this work for the exponent? `int exponent = (int)Math.Log10(Math.Abs(value));` – Matthew Watson Oct 10 '22 at 15:59
  • No built in method. The safest answer is to extract the exponent from binary representation and adjust for normalization ~ https://stackoverflow.com/a/390072/1462295 . Less safely, you can convert to string and parse the result. – BurnsBA Oct 10 '22 at 16:23
  • 1
    @MatthewWatson :) YES THAT DOES!!! – vbbartlett Oct 10 '22 at 20:19
  • maybe it doesn't matter in your use case, but be aware of rounding issues from `Log10`. For example, there are seven values between 99,999 and 100,000 that will yield a value of 5. – BurnsBA Oct 10 '22 at 21:06
  • Nice to know. I don't think it will since I believe all values are fractional values and all in the neg components – vbbartlett Oct 10 '22 at 22:09

0 Answers0