Wednesday, December 22, 2010

Re: Calculating serie of sinus number

Reply to message «Calculating serie of sinus number»,
sent 19:52:14 22 December 2010, Wednesday
by niva:

> 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13
>
> How can I replace easily thoses numbers by sinus value
Assuming you are using vim with python support enabled:
:py from math import sin
:py import vim,re
:py vim.current.line=re.compile(r'\d+\.\d+').sub(lambda match: str(sin(float(match.group(0)))),
vim.current.line)

In pure vimscript this will look like this:
:.s/\d\+\.\d\+/\=string(sin(str2float(submatch(0))))/g
But python solution is much more precise.

No comments: