I've attached a patch to eval.c. It's in unix fileformat so Windows
users may need to first convert it to dos format. Place eval.diff in
your vim72a directory and type something like:
patch -b -p 0 -i eval.diff
Why the patch?
The new version includes a few math functions but is missing many
useful ones.
Both log10() and pow() are present but exp(), fmod() and log() are
missing. (Although fabs() is also missing, the new abs() function
obviates the need for it.
There are trig functions sin(), cos() and atan(). Missing are tan(),
acos(), asin() and atan2(). Also missing are the hyperbolic functions
cosh(), sinh() and tanh().
This patch adds the above missing functions. There are only 10.
I was planning to include the basic trig functions with degree
arguments: dcos(), dsin() and dtan(); and their inverses which return
degrees: acosd(), asind() and atand(). However, I think these are a
frill that are handled nicely in a script with better names, such as
Cos, Sin, Tan, Acos, Asin and Atan. (See the section from my _vimrc
below.)
I've also included an updated version of PG.vim. This Prints
Generalized floating point numbers based the the user's choice of
significant digits with trailing zeros stripped, optional commas,
optional specification of the number of zeros after the decimal point
in a fraction before scientific notation is used, optional stripping
of the zero before the decimal place in a fraction and optional
storing the result being printed in a global variable for reuse later.
Here's part of my current _vimrc which defines the degree based trig
functions mentioned above, a few helper maps for PG() and loading
PG.vim:
if has("float")
let g:pi = 3.14159265358979324
let g:e = 2.71828182845904524
let g:d2r = pi / 180
" Sin, Cos & Tan take degrees as the argument
function Sin(x)
return sin(a:x * g:d2r)
endfunction
function Cos(x)
return cos(a:x * g:d2r)
endfunction
function Tan(x)
return tan(a:x * g:d2r)
endfunction
" Asin, Acos & Atan return degrees as the result
function Asin(x)
return asin(a:x) / g:d2r
endfunction
function Acos(x)
return acos(a:x) / g:d2r
endfunction
function Atan(x)
return atan(a:x) / g:d2r
endfunction
let g:PGdigits = 12
let g:PGzeros = 3
let g:PGlead = 0
let g:PGcommas = 1
let g:PGsavx = 1
cmap <leader>] <home>echo PG(<end>)<enter>
cmap <leader>= <home>PG(<end>)<enter>
so $vim\PG.vim
endif
The zip file assumes you will unzip from the vim directory and the
vim72a directory is immediately below it.
--
Best regards,
Bill
This should be g:pi, surely?
Ben.
Perhaps for clarity - but unless pi were used inside a
function, I don't believe it's necessary. (Inside a
function the reference would fail because a local variable
would be expected.)
However, it's a good idea to be explicit since some day you
may place a fragment of code inside a function.
Thanks, Ben.
--
Best regards,
Bill
Yes; that shows how much attention I was paying; I naturally thought it
*was* inside a function.
Duh...
Ben.