pow function problem

Started by cameyo, October 19, 2020, 02:11:55 AM

Previous topic - Next topic

cameyo

I have some problems with the pow function:
(pow 3 0.33)
;-> 1.436977652184852
(pow -3 0.33)
;-> 1.#IND

In Mathematica (WolframAlpha):
3^0.33 = 1.436977652184852
-3^0.33 = -1.436977652184852

A simple solution:
(define (pow-ext x n)
  (if (< x 0)
      (sub 0 (pow (sub 0 x) n))
      (pow x n)))
(pow-ext 3 0.33)
;-> 1.436977652184852
;(pow-ext -3 0.33)
;-> -1.436977652184852

Why newLISP result is 1.#IND?

Lutz

#1
The newLISP function pow works like the Perl and Python function pow:



>>> pow(3, 0.33)
1.4369776521848516
>>> pow(-3, 0.33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative number cannot be raised to a fractional power
>>>


All use the Standard C Library function pow(a,b) using double floats.

cameyo

#2
Thanks for the explanation