Python math powers?
11-15-2021, 02:14 PM
Post: #1
 robve Member Posts: 215 Joined: Sep 2020
Python math powers?
CASIO fx-CG50 MicroPython v1.9.4 (but may not be specific to this calculator and Python version)

125**(1/3)
4.99999999999999

pow(125,1/3)
4.99999999999999

(-125)**(1/3)
(2.500000000000001+4.330127018922194j)

abs((-125)**(1/3))
5.00000000000001

pow(-125,1/3)
ValueError: math domain error

(-27)**(1/3)
(1.5+2.598076211353316j)

abs((-27)**(1/3))
3.0

- Rob

"I can count on my friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
11-15-2021, 09:57 PM
Post: #2
 Guenter Schink Senior Member Posts: 434 Joined: Dec 2013
RE: Python math powers?
Here's what my Prime G2 does:

(11-15-2021 02:14 PM)robve Wrote:  CASIO fx-CG50 MicroPython v1.9.4 (but may not be specific to this calculator and Python version)
125**(1/3)
4.99999999999999
Prime: 5.0
Quote:pow(125,1/3)
4.99999999999999
Prime: 5.0
Quote:(-125)**(1/3)
(2.500000000000001+4.330127018922194j)
Prime: same
Quote:abs((-125)**(1/3))
5.00000000000001
Prime: 5.0
Quote:pow(-125,1/3)
ValueError: math domain error
Prime: as in (-125)**(1/3)

I think that's almost all correct. Either 4.99.... or 5.0 probably depends on the specific implementation. There has been a lengthy discussion about 3rd root and operators precedence not so long ago.

I've checked the inputs in two other Python interpreters, one on my Samsung Tablet the other on in Windows. They show the same results except that none gives a clear 5.0 like the (probably cheating) Prime.

But all return a valid result for pow(-125,1/3) therefor I'd think this MicroPython on the CASIO is not complete.

HTH Günter
11-15-2021, 10:31 PM
Post: #3
 toml_12953 Senior Member Posts: 1,795 Joined: Dec 2013
RE: Python math powers?
(11-15-2021 09:57 PM)Guenter Schink Wrote:  Here's what my Prime G2 does:

(11-15-2021 02:14 PM)robve Wrote:  CASIO fx-CG50 MicroPython v1.9.4 (but may not be specific to this calculator and Python version)
125**(1/3)
4.99999999999999
Prime: 5.0
Quote:pow(125,1/3)
4.99999999999999
Prime: 5.0
Quote:(-125)**(1/3)
(2.500000000000001+4.330127018922194j)
Prime: same
Quote:abs((-125)**(1/3))
5.00000000000001
Prime: 5.0
Quote:pow(-125,1/3)
ValueError: math domain error
Prime: as in (-125)**(1/3)

I think that's almost all correct. Either 4.99.... or 5.0 probably depends on the specific implementation. There has been a lengthy discussion about 3rd root and operators precedence not so long ago.

I've checked the inputs in two other Python interpreters, one on my Samsung Tablet the other on in Windows. They show the same results except that none gives a clear 5.0 like the (probably cheating) Prime.

But all return a valid result for pow(-125,1/3) therefor I'd think this MicroPython on the CASIO is not complete.

HTH Günter

TI-nspire CX II:

125**(1/3)
5.000000000000002
pow(125,1/3)
5.000000000000002
(-125)**(1/3)
(2.500000000000001+4.330127018922195j)
abs((-125)**(1/3))
5.000000000000001
pow(-125,1/3)
(2.500000000000001+4.330127018922195j)

Tom L
Cui bono?
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)