home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 October / macformat-108.iso / Shareware / Math scientific / PsyScript / libraries / math.lib / math.lib.rsrc / TEXT_2000_Source Text.txt < prev    next >
Encoding:
Text File  |  2001-06-21  |  1.7 KB  |  72 lines

  1. --written by nigel garvey
  2. on rndIEEE(n)
  3.     if (n mod 2) ^ 2 > 0.25 then return n div 0.5 - n div 1
  4.     n div 1
  5. end rndIEEE
  6.  
  7. --sqrt(2)
  8. on sqrt(n)
  9.     return n ^ 0.5
  10. end sqrt
  11.  
  12.  
  13. to average(theList)
  14.     set n to 0
  15.     set tot to 0
  16.     repeat with anItem in theList
  17.         set n to n + 1
  18.         set tot to tot + anItem
  19.     end repeat
  20.     return (tot / n)
  21. end average
  22.  
  23.  
  24. to scale(theList, scaleFactor)
  25.     set outList to {}
  26.     repeat with anItem in theList
  27.         set end of outList to (anItem * scaleFactor)
  28.     end repeat
  29.     return outList
  30. end scale
  31.  
  32. to offsetList(theList, theOffset)
  33.     set outList to {}
  34.     repeat with anItem in theList
  35.         set end of outList to (anItem + theOffset)
  36.     end repeat
  37.     return outList
  38. end offsetList
  39.  
  40. to listMinMax(theList)
  41.     set lmin to item 1 of theList
  42.     set lmax to item 1 of theList
  43.     repeat with anItem in theList
  44.         if anItem < lmin then set lmin to anItem
  45.         if anItem > lmax then set lmax to anItem
  46.     end repeat
  47.     return {lmin, lmax}
  48. end listMinMax
  49.  
  50.  
  51. --written by Paul Berkowitz, March/01
  52. on hex2Dec(hexNum)
  53.     set specChars to {"A", "B", "C", "D", "E", "F"}
  54.     set hexChars to characters of hexNum
  55.     set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, tab}
  56.     set subText to "" & hexChars -- back to text, with tabs
  57.     repeat with i from 1 to 6
  58.         set specChar to item i of specChars
  59.         set AppleScript's text item delimiters to {specChar}
  60.         set textClumps to text items of subText
  61.         set AppleScript's text item delimiters to {"" & (i + 10)}
  62.         set subText to "" & textClumps
  63.     end repeat
  64.     set AppleScript's text item delimiters to {tab}
  65.     set subChars to text items of subText
  66.     set theResult to 0
  67.     repeat with theDigit in subChars
  68.         set theResult to 16 * theResult + theDigit
  69.     end repeat
  70.     set AppleScript's text item delimiters to tids
  71.     return theResult
  72. end hex2Dec