2

How do I take cube roots in emacs lisp? I thought of using fractional exponents like $8^{1/3} = 2$ but I didn't know how to write y as a fraction in (expt x y)

zeynel
  • 129
  • 8

1 Answers1

4

There are a couple of ways:

(expt 8 (/ 1.0 3.0)) ⇒ 2.0

Or, if you want symbolic results:

(require 'calc-arith)
(calcFunc-pow 8 (calcFunc-inv 3)) ⇒ (float 2 0)
(calcFunc-pow 8 (calcFunc-inv (list 'x))) ⇒ (^ 8 (/ 1 (x)))

See also the defmath macro described in chapter 17.5.1 Defining New Functions of the Emacs Calc manual.

db48x
  • 15,741
  • 1
  • 19
  • 23
  • 1
    In the first example it suffices to pass one float so that the output will be a float. In other words, `(/ 1.0 3.0)` is equivalent to `(/ 1.0 3)` and `(/ 1 3.0)`. – aadcg Jan 15 '22 at 07:00