123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- "=============================================================================
- " $Id: float.vim 520 2012-03-19 18:09:15Z luc.hermitte $
- " File: autoload/lh/float.vim {{{1
- " Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
- " <URL:http://code.google.com/p/lh-vim/>
- " License: GPLv3 with exceptions
- " <URL:http://code.google.com/p/lh-vim/wiki/License>
- " Version: 3.0.0
- " Created: 16th Nov 2010
- " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $
- "------------------------------------------------------------------------
- " Description:
- " Defines functions related to |expr-float| numbers
- "
- "------------------------------------------------------------------------
- " Installation:
- " Drop this file into {rtp}/autoload/lh
- " Requires Vim7+
- " History:
- " v2.0.0: first version
- " v3.0.0: GPLv3
- " TODO:
- " }}}1
- "=============================================================================
-
- let s:cpo_save=&cpo
- set cpo&vim
- "------------------------------------------------------------------------
- " ## Misc Functions {{{1
- " # Version {{{2
- let s:k_version = 300
- function! lh#float#version()
- return s:k_version
- endfunction
-
- " # Debug {{{2
- let s:verbose = 0
- function! lh#float#verbose(...)
- if a:0 > 0 | let s:verbose = a:1 | endif
- return s:verbose
- endfunction
-
- function! s:Verbose(expr)
- if s:verbose
- echomsg a:expr
- endif
- endfunction
-
- function! lh#float#debug(expr)
- return eval(a:expr)
- endfunction
-
-
- "------------------------------------------------------------------------
- " ## Exported functions {{{1
-
- " # lh#float#min(list) {{{2
- function! lh#float#min(list)
- let am = lh#float#arg_min(a:list)
- return a:list[am]
- endfunction
-
- function! lh#float#arg_min(list)
- if empty(a:list) | return -1 | endif
- let m = type(a:list[0]) == type(0.0) ? a:list[0] : str2float(a:list[0])
- let p = 0
- let i = 1
- while i != len(a:list)
- let e = a:list[i]
- if type(e) != type(0.0) |
- let v = str2float(e)
- else
- let v = e
- endif
- if v < m
- let m = v
- let p = i
- endif
- let i += 1
- endwhile
- return p
- endfunction
-
-
- " # lh#float#max(list) {{{2
- function! lh#float#max(list)
- let am = lh#float#arg_max(a:list)
- return a:list[am]
- endfunction
-
- function! lh#float#arg_max(list)
- if empty(a:list) | return -1 | endif
- let m = type(a:list[0]) == type(0.0) ? a:list[0] : str2float(a:list[0])
- let p = 0
- let i = 1
- while i != len(a:list)
- let e = a:list[i]
- if type(e) != type(0.0) |
- let v = str2float(e)
- else
- let v = e
- endif
- if v > m
- let m = v
- let p = i
- endif
- let i += 1
- endwhile
- return p
- endfunction
-
-
-
- "------------------------------------------------------------------------
- " ## Internal functions {{{1
-
- "------------------------------------------------------------------------
- let &cpo=s:cpo_save
- "=============================================================================
- " vim600: set fdm=marker:
|