about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-06-02 13:34:59 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-06-02 13:34:59 +0000
commit1cf30c353e753675467c1a3ea198c78bafb5ae0e (patch)
treeda9f51c7a0f64c7e858c0670415757689b528005 /Functions
parentb8ce0ad122a8a86002ecdfb95b735ad4a64c012f (diff)
downloadzsh-1cf30c353e753675467c1a3ea198c78bafb5ae0e.tar.gz
zsh-1cf30c353e753675467c1a3ea198c78bafb5ae0e.tar.xz
zsh-1cf30c353e753675467c1a3ea198c78bafb5ae0e.zip
22480: autoload math functions from zmathfuncdef
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/zmathfuncdef26
1 files changed, 26 insertions, 0 deletions
diff --git a/Functions/Misc/zmathfuncdef b/Functions/Misc/zmathfuncdef
index 0a099300f..21d3c249e 100644
--- a/Functions/Misc/zmathfuncdef
+++ b/Functions/Misc/zmathfuncdef
@@ -35,6 +35,32 @@ done
 
 functions -M $mname $iarg $ioptarg $fname || return 1
 
+# See if we need to autoload a math function from the standard
+# library.
+if ! zmodload -e zsh/mathfunc; then
+  local -a mathfuncs match mbegin mend loads
+  local mathfuncpat bodysearch
+
+  # generate pattern to match all known math functions
+  mathfuncs=(abs acos acosh asin asinh atan atanh cbrt ceil cos cosh erf erfc
+    exp expm1 fabs float floor gamma int j0 j1 lgamma log log10 log1p logb
+    sin sinh sqrt tan tanh y0 y1 signgam copysign fmod hypot nextafter jn yn
+    ldexp scalb rand48)
+  mathfuncpat="(${(j.|.)mathfuncs})"
+  bodysearch=$body
+  while [[ $bodysearch = (#b)(*[^[:alnum]]|)([[:alnum:]]##)\((*) ]]; do
+    # save worrying about search order...
+    bodysearch=$match[1]$match[3]
+    if [[ $match[2] = ${~mathfuncpat} ]]; then
+      # Uses function from math library.
+      loads+=($match[2])
+    fi
+  done
+  if (( ${#loads} )); then
+    zmodload -af zsh/mathfunc $loads
+  fi
+fi
+
 {
   eval "$fname() { (( $body )) }"
 } always {