Post Reply 
AVars parsing bug or limitation
03-28-2024, 07:06 AM (This post was last modified: 03-28-2024 08:54 AM by komame.)
Post: #10
RE: AVars parsing bug or limitation
(12-17-2023 10:02 PM)ab3ap Wrote:  Thank you, Piotr, I will give it a try right after sending this. It sounds perfect and many thanks for finding a better solution!

Mike,
I found an even better solution, completely independent of the formatting settings and digit grouping in HOME.

Code:
import cas

def numToAvars(varName, val):
    cas.caseval('AVars("%s"):=%s' % (varName,str(val)))

As you can see, instead of using hpprime.eval, I used cas.caseval. This allows parsing to be done on the CAS side, which handles all numerical cases perfectly. There's no need to even specify the output format (%.11f); simple conversion through str is sufficient.

numToAvars('v',val) → val stored in AVars "v" variable

examples:
Code:
numToAvars('v',123e+3) → 123000
numToAvars('v',-0.000000000000000000000000000001234) → −1.234ᴇ−30
numToAvars('v',1234000000000000000000000000000) → 1234ᴇ30

Additionally, positive and negative infinity values are also supported:

Code:
numToAvars('v',float('inf')) → +Inf
numToAvars('v',float('-inf')) → -Inf
numToAvars('v','∞') → +Inf
numToAvars('v','-∞') → -Inf

I think it's time to update your Prime Python page Wink

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
AVars parsing bug or limitation - ab3ap - 11-14-2023, 04:08 PM
RE: AVars parsing bug or limitation - komame - 03-28-2024 07:06 AM



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