Author Topic: FIX issue  (Read 6453 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: FIX issue
« Reply #15 on: April 23, 2021, 11:26:43 AM »
Code: [Select]
: (setq Prec 100000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec)  => 0.3456

: (setq Prec 10000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec) => 0.345599999999999

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: FIX issue
« Reply #16 on: April 23, 2021, 02:08:51 PM »
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.

Code - Auto/Visual Lisp: [Select]
  1. (defun fix2 ( x ) (fix (+ x 1e-8)))

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: FIX issue
« Reply #17 on: April 23, 2021, 02:12:57 PM »
Also I believe AutoLisp only holds 16 digits of significance for real numbers.

It is worth noting that this is an inherent limitation of the double-precision floating-point format used by AutoLISP to store the 'real' data type, not specifically a limitation of AutoLISP:
The 53-bit significand precision gives from 15 to 17 significant decimal digits precision (2−53 ≈ 1.11 × 10−16).

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: FIX issue
« Reply #18 on: April 23, 2021, 02:16:16 PM »
I need to convert degrees in sexagesimal format to radians.

Have you considered the angtof function?

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: FIX issue
« Reply #19 on: April 23, 2021, 04:45:05 PM »
I need to convert degrees in sexagesimal format to radians.

Have you considered the angtof function?

(defun :GGMMSS>RAD   (ggmmss / gg mm mmss mmss-100 ss)
   (setq   gg        (float (fix ggmmss) )
           mmss      (- ggmmss gg)
           mmss-100  (* mmss 100.0)
           mm        (float (fix mmss-100) )
           ss        (- mmss-100 mm)
           ss        (* ss 100.0)
   )
   (/ (*   (+ gg (/ mm 60.0) (/  ss 3600.0) )   pi) 180.0)
)

123.4567 is a SEXAGESIMAL angle  123° 45' 67''

I want convert it in RADIANTS

(:GGMMSS>RAD 123.4567) =  2.16017   (2.1601697745093262)


- - - - - - - - - - - - - - - - - - - - -

(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 !

d2010

  • Bull Frog
  • Posts: 323
Re: FIX issue
« Reply #20 on: April 23, 2021, 04:54:38 PM »
Can you execute my lisp?>
:yes:
Code: [Select]
(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)


Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: FIX issue
« Reply #21 on: April 23, 2021, 07:01:43 PM »
(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 !

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.
Code - Auto/Visual Lisp: [Select]
  1. _$ (rtos (angtof "123d45'67\"" 1) 2 15)
  2. "2.160169774509326"

danAllen

  • Newt
  • Posts: 132
Re: FIX issue
« Reply #22 on: April 23, 2021, 08:49:56 PM »
It is worth noting that this is an inherent limitation of the double-precision floating-point format used by AutoLISP to store the 'real' data type, not specifically a limitation of AutoLISP:
The 53-bit significand precision gives from 15 to 17 significant decimal digits precision (2−53 ≈ 1.11 × 10−16).

trying to understand why (- 12.3456 12) = 0.345599999999999

I searched for "convert decimal to Double-precision floating point" and found this:
https://www.h-schmidt.net/FloatConverter/IEEE754.html

entering 12.3456 & 12 gets the following. I don't understand it but now I have a little insight into why the math acts strangely.





domenicomaria

  • Swamp Rat
  • Posts: 723
Re: FIX issue
« Reply #23 on: April 24, 2021, 01:24:37 AM »
Quote
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"


Ok.
But what have I to do to FORMAT the INPUT for ANGTOF  ?

ANGTOS returns the following results,


(ANGTOS 123.4567 0) = "233.548"
(ANGTOS 123.4567 1) = "233d32'52\""
(ANGTOS 123.4567 2) = "259.498g"
(ANGTOS 123.4567 3) = "4.076r"
(ANGTOS 123.4567 4) = "S 36d27'8\" W"

and never returns what i need : "123d45'67\""
. . .

If it required that I have to produce "123d45'67\""  "manually"
it means that I have before to extract the degrees, the minutes and the seconds . . .
convert them into strings and at the end,
format it in this way : "123d45'67\""
. . .
but at this point, in this situation,
(a number like this 123.4567, that means 123° 45' 67'')
(I acquire this data from a surveying instrument, in this format)
ANGTOS and ANGTOF are not useful . . .

and I prefer to use my well working :GGMMSS>RAD

GGMMSS>RAD doesn't use any conversion to string.

And this is RIGHT for a MATH issue.
« Last Edit: April 24, 2021, 01:44:09 AM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: FIX issue
« Reply #24 on: April 24, 2021, 01:49:37 AM »
Code: [Select]
: (setq Prec 100000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec)  => 0.3456

: (setq Prec 10000)
: (/ (- (* Prec 12.3456) (* Prec 12)) Prec) => 0.345599999999999

interesting !

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: FIX issue
« Reply #25 on: April 24, 2021, 01:50:43 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun fix2 ( x ) (fix (+ x 1e-8)))

Interseting !

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: FIX issue
« Reply #26 on: April 24, 2021, 10:38:40 AM »
(a number like this 123.4567, that means 123° 45' 67'')
(I acquire this data from a surveying instrument, in this format)
is this data stored in a binary file?

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: FIX issue
« Reply #27 on: April 24, 2021, 01:50:20 PM »
(a number like this 123.4567, that means 123° 45' 67'')
(I acquire this data from a surveying instrument, in this format)
is this data stored in a binary file?
it is stored in an ascii file, a simple txt file

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: FIX issue
« Reply #28 on: April 24, 2021, 04:08:05 PM »
reading your comments, i understand that i didn't explain well what the problem is.

I have a text file that contains a set of data representing a points cloud.

The used (cheap, Chinese, but still reliable and accurate) topographic instrument is configured to return
degrees in sexagesimal format.

But these degrees in sexagesimal format
are written NOT in the true standard sexagesimal format.

But they are written in an APPARENT decimal format.

Then, in this situation,
123.4567
means
123° 45' 67''

And since I need to convert it to radians,
first I have to extract the degrees, minutes and seconds.

Then apply the conversion formula from sexagesimal to decimal degrees
degrees + minutes/60 + seconds/3600
and then convert these degrees from decimal format to radians.

I realize that due to the particularity of the initial format,
everything can be misunderstood.

I hope I have explained well.

And thank you all for the suggestions you give me.

ciao
« Last Edit: April 24, 2021, 04:26:11 PM by domenicomaria »

danAllen

  • Newt
  • Posts: 132
Re: FIX issue
« Reply #29 on: April 24, 2021, 04:39:37 PM »
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