Post Reply 
HP Prime complex division problem in CAS
11-19-2020, 07:08 AM
Post: #2
RE: HP Prime complex division problem in CAS
I wrote cdiv() as a workaround for the dynamic range problem of complex division in CAS.
It works fine in CAS as follows.

cdiv(1e307+2e307*i, 2e307+1e307*i) → 0.8+0.6*i

Code:
#CAS
// cdev -- complex division. returns x / y.
// This is a workaround for the dynamic range problem of complex division in CAS.
// Conforms to HP Prime software version 2.1.14433 (2020 01 21).
cdiv(x, y):=
BEGIN
  LOCAL u, v;
  IF abs(RE(y)) >= abs(IM(y)) THEN
    u := IM(y) / RE(y); 
    v := 1 / (RE(y) + IM(y) * u);
    return (RE(x) + IM(x) * u) * v + (IM(x) - RE(x) * u) * v * i;
  ELSE
    u := RE(y) / IM(y); 
    v := 1 / (RE(y) * u  + IM(y));
    return (RE(x) * u + IM(x)) * v + (IM(x) * u - RE(x)) * v * i;
  END;
END;
#END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP Prime complex division problem in CAS - lyuka - 11-19-2020 07:08 AM



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