Re: limiting numeric runs
Re: limiting numeric runs
- Subject: Re: limiting numeric runs
- From: has <email@hidden>
- Date: Fri, 10 Jan 2003 15:43:12 +0000
Paul Skinner wrote:
Indeed. I should have supplied real testing data with the question.
[...]
<real>0.76713436841964722</real>
It'd have helped. (e.g. I thought you were working with large
mixed-text-and-number strings, hence the character-by-character
approach and general complaints about speed.)
This is really junky (may also be buggy; I haven't tested it
thoroughly enough) but may be "good enough" for the task you describe:
======================================================================
--precision limits
property dLen : 16 -- safe max=~16
property mLen : 12 -- safe max=~12
on realStrToReal(str)
if str's first character is "-" then
set mlt to -1
set str to str's text 2 thru -1
else
set mlt to 1
end if
set AppleScript's text item delimiters to "."
set {d, m} to (str & ".0")'s text items
if d's length is greater than dLen then
set d to (d's text 1 thru dLen) & "E+" & ((d's length) - dLen)
return ((d as real) * mlt)
else
if m's length is greater than mLen then
set m to m's text 1 thru mLen
end if
set m to ("0." & m) as real
return (((d as real) + m) * mlt)
end if
end realStrToReal
======================================================================
No error checking/trapping; assumes the initial string is a valid
number in plain, not sci, notation; takes some liberties in its
treatment of numbers. (You'd have to check the plist documentation to
see if such assumptions are acceptable or not.)
Unfortunately half the time is still HUGE when processing a large
body of text.
Have you profiled the script as a whole? Unless/until you've
identified specific bottlenecks, there's little point optimising
individual components.
has
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.