: (setq x-deg 12.3456 )
12.3456
: (setq i-deg (fix x-deg) )
12
: (setq sub-deg (- x-deg i-deg) )
0.345599999999999
: (setq sub-deg-10000 (* sub-deg 10000.0) )
3455.99999999999
: (setq i-sub-deg-10000 (fix sub-deg-10000 ) )
3455
last line :
try (it won't influence on integer result, but it will fix an issue) :
(setq i-sub-deg-10000 (fix (+ sub-deg-10000 0.01)) )
;;;==========================================================
;;;Rounding function - Joe Burke - 2/23/03
;;;==========================================================
(defun SAA_round (value to)
(if (zerop to) value
(* (atoi (rtos (/ (float value) to) 2 0)) to))
)
: (saa_round 3455.99999999999 1)
3456
(saa_round 3455.99999999999 1) -> 3456
: (setq i 1)
1
: (repeat 16 (princ (strcat "\n" (rtos (+ (setq i (* i 10)) pi) 2 32))))
13.14159265358979
103.1415926535898
1003.141592653590
10003.14159265359
100003.1415926536
1000003.141592654
10000003.14159265
100000003.1415927
1000000003.141593
10000000003.14159
100000000003.1416
1000000000003.142
10000000000003.14
100000000000003.1
1000000000000003
1.000000000000000
: (setq i 1)
1
: (repeat 16 (princ (strcat "\n" (rtos (- (+ (setq i (* i 10)) pi) i) 2 32))))
3.141592653589793
3.141592653589797
3.141592653589782
3.141592653590124
3.141592653584667
3.141592653584667
3.141592653468251
3.141592651605606
3.141592621803284
3.141592025756836
3.141586303710938
3.141601562500000
3.140625000000000
3.140625000000000
3.125000000000000
4.000000000000000
This issue arises because a computer has finite memory in which data may be stored, and consequently not all numbers can be represented exactly, but instead must be approximated and stored in an agreed format (specifically, in this case, the double-precision floating-point format, or simply 'double') which has inherent compromises at the extent of its precision in order to be useful under a wide range of applications (i.e. affording an ability to represent both very large numbers (to an order of magnitude of 1e308) with low precision, and very small numbers with high precision).
…Sexagesimal format is : 123°34'56" :-o
I need to convert degrees in sexagesimal format to radians.
Is there a mathematical-only solution in VLISP?
: (- 12.3456 12)
0.345599999999999
: (- 12.3456 12.0)
0.345599999999999
: (- 12.3 12)
0.300000000000001
: (setq Prec 100000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec) => 0.3456
: (setq Prec 10000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec) => 0.345599999999999
And for that I think someone should implement another version
of the FIX command with limitations.
But within these limits, the command should work well.
Also I believe AutoLisp only holds 16 digits of significance for real numbers.
The 53-bit significand precision gives from 15 to 17 significant decimal digits precision (2^{−53} ≈ 1.11 × 10^{−16}).
I need to convert degrees in sexagesimal format to radians.
I need to convert degrees in sexagesimal format to radians.
Have you considered the angtof (http://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-9DE9200B-F27E-4BB6-8AE6-BC5C8A64A527) function?
(Defun dfn_real_rtos (x151 unitstar / rr a b od r dz x)
(setq;|a580492|;
x x151
unitstar (if (numberp unitstar) (abs unitstar) (getvar "LUNITS"))
dz "DIMZIN") (if (or (= unitstar 4) (= unitstar 5)) (setq;|a580602|;
$rr (rtos x)) (progn (setq;|a580642|;
od (getvar dz)) (setvar dz (boole 1 od (~ 8))) (setq;|a580694|;
a (rtos x)) (setvar dz (boole 7 od 8)) (setq;|a580744|;
b (rtos x unitstar 15)) (setvar dz od) (setq;|a580804|;
$rr (if (equal (distof a) (distof b) 0.000001) a b))))
$rr)
(ANGTOF string [units])
0 - Degrees
1 - Degrees/minutes/seconds
2 - Grads
3 - Radians
4 - Surveyor's units
I don't know how to FORMAT the INPUT for ANGTOF
(ANGTOF "123.4567" 3) = 4.07618
but it is a WRONG RESULT !
It is worth noting that this is an inherent limitation of the double-precision floating-point format (https://en.wikipedia.org/wiki/Double-precision_floating-point_format) used by AutoLISP to store the 'real' data type, not specifically a limitation of AutoLISP:Quote from: https://en.wikipedia.org/wiki/Double-precision_floating-point_formatThe 53-bit significand precision gives from 15 to 17 significant decimal digits precision (2^{−53} ≈ 1.11 × 10^{−16}).
Lee Mac :
You have not read the documentation for the angtof function that I linked above -
the function will always return a value in radians
and the units argument represents the format of the supplied string,
not the output.
(rtos (ANGTOF "123d45'67\"" 1) 2 15) = "2.160169774509326"
Code: [Select]: (setq Prec 100000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec) => 0.3456
: (setq Prec 10000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec) => 0.345599999999999
Code - Auto/Visual Lisp: [Select]
(a number like this 123.4567, that means 123° 45' 67'')is this data stored in a binary file?
(I acquire this data from a surveying instrument, in this format)
it is stored in an ascii file, a simple txt file(a number like this 123.4567, that means 123° 45' 67'')is this data stored in a binary file?
(I acquire this data from a surveying instrument, in this format)
(defun sgf_convert (n / )
(+ (atoi (substr n 1 (vl-string-search "." n)))
(/ (atoi (substr n (+ 2 (vl-string-search "." n)) 2)) 60.0)
(/ (atoi (substr n (+ 4 (vl-string-search "." n)) 2)) 3600.0)
)
)
(defun dtr (a)(* pi (/ a 180.0)))
(sgf_convert "123.4567") -> 123.768611111111
(dtr (sgf_convert "123.4567")) -> 2.16016977450933
Just a ps degs max 360, Minutes max 60, seconds max 60, can not have 67.yes
does this work?Code: [Select](defun sgf_convert (n / )
(+ (atoi (substr n 1 (vl-string-search "." n)))
(/ (atoi (substr n (+ 2 (vl-string-search "." n)) 2)) 60.0)
(/ (atoi (substr n (+ 4 (vl-string-search "." n)) 2)) 3600.0)
)
)
(defun dtr (a)(* pi (/ a 180.0)))
(sgf_convert "123.4567") -> 123.768611111111
(dtr (sgf_convert "123.4567")) -> 2.16016977450933
assumes always 4 digits after decimal, and since you are reading from a file you are starting with a string
does this work?Code: [Select](defun sgf_convert (n / )
(+ (atoi (substr n 1 (vl-string-search "." n)))
(/ (atoi (substr n (+ 2 (vl-string-search "." n)) 2)) 60.0)
(/ (atoi (substr n (+ 4 (vl-string-search "." n)) 2)) 3600.0)
)
)
(defun dtr (a)(* pi (/ a 180.0)))
(sgf_convert "123.4567") -> 123.768611111111
(dtr (sgf_convert "123.4567")) -> 2.16016977450933
assumes always 4 digits after decimal, and since you are reading from a file you are starting with a string
I prefer to not use strings.
But it works.
Bravo !