A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

11

v x 10 RET should do it. Uses calc-index.


6

You can use the built-in calc package to do so. Mark your expression, e.g. 3 * (1 + 1) Call calc-grab-region Call calc-dispatch (default C-x *), then hit g


6

Yes, for example: (calc-eval "solve([x+y=3, x-y=1], [x,y])") evaluates to: "[x = 2, y = 1]" You might find it more comfortable to use a calc-mode buffer than running calc-eval in the scratch buffer, though.


6

The same Emacs Rocks page links to an implementation of eval-and-replace used to replace a sexp with its value in this episode.


5

I'm having exactly the same issue, anything I try to fit gives me the same complaint. I stumbled across this though, which just says it's a bug in 24.3 and fixed in 24.4.


5

The idea is to evaluate some Elisp inline and replace it with the result. It looks like he did it with a custom function he defined and bound to C-x C-e. Note that C-x C-e is bound to eval-last-sexp by default, which does something very similar. It evaluates the s-expression just before your cursor. If you call it with a prefix argument, it will paste the ...


5

You could use hook calc-end-hook to hook delete-frame. emacsclient -t --eval '(progn (add-hook (quote calc-end-hook) (lambda () (delete-frame))) (calc nil t))'


5

I'm not sure about the actual reason plus won't work the way you expect, but this is what Calc does when you add vectors interactively: #+BEGIN_SRC calc :var X=[1 2], Y=[3 4] map(add, X, Y) #+END_SRC The result where you get [[4, 6]] seems to indicate that Calc needs vectors to be 2D matrices with a single column, rather than 1D matrices.


4

Update (Oct 12 2015) Below calc-yank implementation is now added to emacs trunk. It will be available in the next stable emacs release. I reviewed the original definition of calc-yank and the good thing is that it does not have any argument. So I added my own argument, radix, and slightly modified how the let-bound var thing is derived. By default, the ...


4

Using Org-mode Select the text of the table. C-c | Add at the bottom: #+TBLFM: $6=$6+5.487 and press C-c C-c while the point is either on the formula or on the table. This gives: | ATOM | 10 | H5 | LIG | 1 | 4.803 | 2.034 | 0.000 | 1.00 | 0.00 | | ATOM | 11 | C1 | LIG | 1 | 6.461 | 0.686 | 0.000 | 1.00 | 0.00 | | ATOM | 12 | H1 | LIG | 1 | 7.221 | 1....


4

To input a value in non-standardized HMS form you can press ' to start algebraic entry and then use the hms function. For example, to enter the equivalent of 0@8000'0" you would type ' hms(0, 8000, 0) RET. Another possibility is to input the number of days and then convert them to HMS form using the function calc-to-hms (bound to ch). So for your example ...


4

(calc) Basic Arithmetic: When combining multiplication and division in an algebraic formula, it is good style to use parentheses to distinguish between possible interpretations; the expression a/b*c should be written (a/b)*c or a/(b*c), as appropriate. Without the parentheses, Calc will interpret a/b*c as a/(b*c), since in algebraic entry Calc ...


3

How can I input this command? I believe you cannot. I am convinced that this is a bug in org-babel-execute:calc: see ob-calc.el, line 67. org-babel-execute:calc expects every Calc "stack operation" to be a function taking a prefix argument which specifies the number of times it is applied. calc-divide, for example, takes a prefix argument, so line 3 of ...


3

You can always use M-x query-replace-regexp, if you're comfortable with regexps and elisp. Replacing: ^\(\(?:[^ ]+ +\)\{5\}\)\([ -][0-9.]+\) With: \1\,(format "% .3f" (+ 5.487 \#2)) Will replace the second captured group (being the 6th column) with the formatted result of the calculation. This will break the alignment slightly if the numbers get too ...


3

You can use multiple cursors to get this done. Before you get started with the below steps, add this to your init.el, evaluate it and bind it to a key binding of your linking. ;; http://stackoverflow.com/questions/3035337/in-emacs-can-you-evaluate-an-emacs-lisp-expression-and-replace-it-with-the-resul (defun eval-and-replace-last-math-sexp () "Replace an ...


3

This question is almost a duplicate to the question about the usage of a calc table for converting units. The only difference is that you do not only want to convert values with units in a column but you want the result of an operation with standard units. You can write the operation into the first inner calc-eval of the linked answer. | test | ...


3

Original question: Is it possible that the evaluation of ((x-1)/(x+1))+((x+1)/(x-1))=> returns ((x-1)/(x+1))+((x+1)/(x-1))=>(2 x^2 + 2) / (x^2 - 1) The calc function nrat transforms its expression argument to a rational expression. You can try nrat(((x-1)/(x+1))+((x+1)/(x-1))) with M-: (calc-eval "nrat(((x-1)/(x+1))+((x+1)/(x-1)))") The result is: (2*...


3

The following works for me: | | Fund A | Fund B | Fund C | Combined | |-----------+--------+--------+--------+----------| | US | .1 | .8 | .5 | 0.53 | | Europe | .2 | .1 | .4 | 0.19 | | Pacific | .7 | .1 | .1 | 0.28 | | Weighting | .3 | .5 | .2 | | #+TBLFM: @2$>..@&...


2

Found the solution as soon as I posted the question .. Solution In my init.el: (require 'calc) (setq calc-settings-file (concat user-emacs-directory "/setup-calc-defaults.el")) In my setup-calc-defaults.el: (setq calc-float-format '(eng 0)) The defaults don't become effective right-away. Without worrying about what all packages I might need to require ...


2

Check out section 11.6 of the Calc manual, which is about solving equations. I just use calc-mode rather than calling calc-eval by hand, but it seems like you'd be able to use the functions it describes.


2

As it says in the documentation of calc-eval, Return value will either be the formatted result in string form, or a list containing a character position and an error message in string form. So check whether the return value is a string or a list. If it's a list, don't modify the buffer. Some other improvements: Don't force the loading of calc. calc-...


2

Have the region -2:5 in a buffer. C-0 C-x * e activates calc's embedded mode on that region. Activate calc-latex-language by typing d L if not already done. The marked text has been replaced by \frac{-2}{5}. Key sequence C-x * e deactivates embedded mode. So I think it's possible to write a command that checks for fractions like -2:5 in a column of an ...


2

After analize the documentation of Algebraic Entry I manage to find the reference to the original function and realized that, in fact, it just toggles the mode on and off. Then, using the help system(C-h f calc-total-algebraic-mode) I could verify that the keys binding to this function actually are M-m m-t. So, to exit from the total algebraic mode in ...


2

You might also use calc's embedded mode if you intent to replace an expression with its result in the current buffer. C-u C-x * e when your formula / expression is on it's own on a separate line. Otherwise mark it and type C-0 C-x * e (Update: thanks to Dodgie, forgot to mention that) When you are finished with your mathematical manipulations type C-x * e ...


2

You first have to evaluate the algebraic 7i - 2 by pressing =, such that it is rewritten as (-2, 7). Then you can use calc-abs just like you would on a normal number. See also the section on complex formats in the Calc manual.


2

In calc, you can perform this operation as follows: type your number to check (e.g. 16#32FE) keep odd numbered bits: 16#AAAA b a. This ands your number with 0xAAAA binary unpack with b u. This returns a list of active bits. count length of list with V # check for parity: 2% Turning this into a macro... (currently reading the manual).


2

Looks like you have composed characters (^U is composed to Û). That is usually already controlled by the OS. Just hit the spacebar after typing ^ to get a caret as input character.


2

I'm looking for a way to do calculations within Emacs where 50/10*100 evaluates to 500 Set calc-multiplication-has-precedence to nil, then calc (and quick-calc) will do that. (calc) Customizing Calc -- Variable: calc-multiplication-has-precedence The variable calc-multiplication-has-precedence determines whether multiplication has precedence ...


2

#x1234 is just a hex number and not a byte-encoding. You can easily define a byte encoding yourself. For an instance with the following my-byte-decode function: (defun my-byte-decode (list) "Decode hex number big-endian encoded as sequence of bytes in a list." (cl-reduce (lambda (hi lo) (+ (* #x100 hi) lo)) list)) You can decode a little endian encoded ...


1

One way of going from an HMS form to the number of seconds is hinted by a line from the HMS forms page: Dividing two HMS forms produces a real-valued ratio of the two angles. So if an HMS form is on the stack 5@ 30' 0" entering one second to the stack 1" and dividing by it / gives the number of seconds: 19800. Not exactly a convert but it's only ...


Only top voted, non community-wiki answers of a minimum length are eligible