Code Red > AutoLISP (Vanilla / Visual)
Challenge - Real number precision?
CAB:
If you get user input for a real number, how would you determine the precision of the number entered?
Examples of user enters:
0.007
1.05
.1
sinc:
--- Quote from: CAB on November 02, 2006, 07:37:47 PM ---If you get user input for a real number, how would you determine the precision of the number entered?
Examples of user enters:
0.007
1.05
.1
--- End quote ---
How about the precision of:
10
579000
579000.0
Are those included in the challenge? (not that I'll have time to work on it..)
CAB:
Sure, and I wish you had the time. :-)
Derwin:
my solution:
--- Code: ---; ----------------------------------------------------------------------------
; memeeng 031106 returns precision of given number
;
(defun whatprec ( VAL )
(if (= 0 (- VAL (fix VAL)))
0
(progn
(setq SVAL (rtos VAL 2))
(setq SVAL (substr SVAL (+ 2(vl-string-search "." SVAL))))
;strip off RH '0'
(while (= "0" (substr SVAL (strlen SVAL) 1))
(setq SVAL (substr SVAL 1 (1-(strlen SVAL)) )) )
(strlen SVAL)
);endPROGN
);endIF
)
--- End code ---
Derwin:
hmm, one thing:
the result will only go as high as "LUPREC" will allow, ACAD2004=8 places.
ie: (setvar "LUPREC" 8)
maybe for deeper precision a set of comparrisons with .000000001, .0000000001 etc would work better..
Navigation
[0] Message Index
[#] Next page
Go to full version