Thanks for your work on this block calculator. As is, it
will not work for Windows shells (cmd and 4nt).
BC uses '^' to raise a number to an integer power. That's
the escape character for both Windows shells. So to compute
2^10, you would write for 4nt:
MyCalc 2^^10
For cmd, and I'll let cmd users explain this one - it
appears to be parsing this twice, write:
MyCalc 2^^^^10
I've also added rounding for the Windows version. I keep
the 'nix version as it was (except I formatted it to fit in
email and replaced your g:MyCalcPresition with g:bc_scale.
This is the number of digits after the decimal point.
I've testing this with GNU bc 1.06. Here's the modified
function:
function MyCalc(str)
if has("win32")
if &shell =~? "cmd\.exe"
return system("echo x=".a:str
\.";d=.5/10^^^^".g:bc_scale
\.";if(x^^^<0)d=-d;x+=d;scale="
\.g:bc_scale.";print x/1|bc -l")
else
return system("echo x=".a:str
\.";d=.5/10^^".g:bc_scale
\.";if(x^<0)d=-d;x+=d;scale="
\.g:bc_scale.";print x/1|bc -l")
endif
else
return system("echo \'scale=" . g:bc_scale
\ . " ; print " . a:str . "\' | bc -l")
endif
endfunction
I have no way of testing this, but I think the 'nix version
with rounding would look like this:
return system("echo \'x=".a:str
\.";d=.5/10^^".g:bc_scale
\.";if(x^<0)d=-d;x+=d;scale="
\.g:bc_scale.";print x/1\'|bc -l")
One more thing, you define a 'vmap' followed by a 'map' for
the same lhs. The 'map' overrides the 'vmap'. You could
simply replace 'map' with 'nmap' - but that doesn't define
the operator pending functionality - I don't think I need
that. If you do, an alternate would be to define the 'map'
before the 'vmap'.
--
Best regards,
Bill