@karolus
I don't have LibreOffice, but I'm curious to understand what these formulas aim to do, especially in terms of what @Lupp is trying to do.
@MrProgrammer
Thank you for another CALC trick! TIME is a pretty slick way to use DMS numbers. It looks like TIME sees the unit value as 24 hours with a base 60 fraction. I'll keep it in mind as I'm working on this spreadsheet and others. Since converting to a TIME-based format would involve other spreadsheets and commercial software that I use, I don't think I can convert my input format, but it might be good for calculation purposes, output, or to save a step or two in cell formulas.
@MrProgrammer,
Yes! I remember our conversation of 6 years ago and I did start using the MOD command. Thank you! It made some things a lot easier. I do continue to use QuadNE for some purposes. Here is a sample of the spreadsheet. It's not fully operational, but getting closer. Again, its purpose is a proportional distribution of error in angle and distance measurements of a polygon on the face of the (assumed flat) earth.
I did get the dectodms macro working. @FJCC pointed out both a logical problem and a precision-rounding problem with it when I first posted. I seem to have repaired the algorithm logic and worked around the rounding problem. The rounding problem is demonstrated by the first print statement in the macro below. In summary, and using the example of -4.3 as an argument, BASIC results are that
ABS(-4.3)-INT(ABS(-4.3)) ~ 0.29999999
and then INT(100 X 29.999999) = 29
Maybe this is due to precision limits in binary floating point arithmetic in BASIC. Making the variables DOUBLE precision lowers that precision error, but doesn't eliminate it.
In modifying the above formula, I get
FIX(ABS(-4.3)x100-INT(ABS(-4.3)) x 100) = 30
as desired. I tested the macro with 8 or 10 examples, and rounding errors did not occur.
If you run the following macro, some of the print statements offer insight to the rounding issue.
Code: Select all
REM ***** BASIC *****
Option Explicit
Function dmstodec(Optional a)
REM works 2-1-2023
REM D. Sperduto
REM do not declare function name - it will zap its value
Dim seconds as Double
Dim absa as Double
Dim absang as Double
Dim intega as Double
Dim minutes as Double, intsign as Double, secondsrough as Double
a=-4.3
print (abs(a)-int(abs(a)))*100, fix(((abs(a)-int(abs(a)))*100)
absa=abs(a)
intega=int(absa)
REM write intega
REM write abs(a)-int(a)
REM write fix(abs(a))
REM print (abs(a)-int(abs(a)))*100, (absa-intega)*100
REM write abs(a)*1000000000000000, int(abs(a))*10000000000000000
minutes=fix(absa*100-intega*100)
secondsrough=(absa-intega)*100-minutes
seconds=(absa*100-intega*100-minutes)*100
absang=intega+(minutes/60)+(seconds/3600)
dmstodec=absang*sgn(a)
REM print a, absa, intega, minutes, secondsrough, seconds, absa-intega
print dmstodec
End Function
I did try solving the DMS to decimal task by some text handling commands in CALC formulas. I got pretty close, but it turns out there is a bug (it seems) in the MID command. When I use it like this
MID("4.3000);SEARCH(".";E23)+1;2)
the formula returns "3". It should return "30".
After banging around for a few hours trying to get past this problem, I threw down my hands (previously I had thrown them UP) and plowed through with the macro instead. I really like that I can use it like a simple function that does the whole task, instead of a long formula I have to paste into other long formulas.