rdfs:comment
| - Equations can span multiple lines, and the full bc syntax is probably supported. Additionally, sin (), cos (), etc, are transformed into the names used by bc (s () c (), etc). Here are some example lines: 2 * sqrt (2) = 3 * (2 - 1) + 4.0 ^ 6 = 4 / 3 = 3 + 4 - 2 * (1 / (3 + 2)) = define rad (x) { return (x / 180) * 4 * atan (1) } cos (rad (45)) = Select each of these in turn and hit ;bc for each. This is what you get: Here is the code you need to put in your vimrc file:
|
abstract
| - Equations can span multiple lines, and the full bc syntax is probably supported. Additionally, sin (), cos (), etc, are transformed into the names used by bc (s () c (), etc). Here are some example lines: 2 * sqrt (2) = 3 * (2 - 1) + 4.0 ^ 6 = 4 / 3 = 3 + 4 - 2 * (1 / (3 + 2)) = define rad (x) { return (x / 180) * 4 * atan (1) } cos (rad (45)) = Select each of these in turn and hit ;bc for each. This is what you get: 2 * sqrt (2) = 2.82842712474619009760 3 * (2 - 1) + 4.0 ^ 6 = 4099.000000 4 / 3 = 1.33333333333333333333 3 + 4 - 2 * (1 / (3 + 2)) = 6.60000000000000000000 define rad (x) { return (x / 180) * 4 * atan (1) } cos (rad (45)) = .70710678118654752440 Here is the code you need to put in your vimrc file: vnoremap ;bc "ey:call CalcBC() function! CalcBC() let has_equal = 0 " remove newlines and trailing spaces let @e = substitute (@e, "
", "", "g") let @e = substitute (@e, '\s*$', "", "g") " if we end with an equal, strip, and remember for output if @e =~ "=$" let @e = substitute (@e, '=$', "", "") let has_equal = 1 endif " sub common func names for bc equivalent let @e = substitute (@e, '\csin\s*(', "s (", "") let @e = substitute (@e, '\ccos\s*(', "c (", "") let @e = substitute (@e, '\catan\s*(', "a (", "") let @e = substitute (@e, "\cln\s*(", "l (", "") " escape chars for shell let @e = escape (@e, '*()') " run bc, strip newline let answer = substitute (system ("echo " . @e . " \| bc -l"), "
", "", "") " append answer or echo if has_equal == 1 normal `> exec "normal a" . answer else echo "answer = " . answer endif endfunction
|