Post Reply 
Which systems support a COMPLEX data type?
07-19-2023, 12:24 AM
Post: #21
RE: Which systems support a COMPLEX data type?
In R language:

Code:

a <- sqrt(-1 + 0i)            # sqrt(-1) doesn't work → Warning message: In sqrt(-1) : NaNs produced
b <- 2-3i                     # (2 -3i) is possible
c <- 42

d <- a + b + c

print(d)

result: 44 − 2i

Bruno
Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G
Find all posts by this user
Quote this message in a reply
07-19-2023, 02:14 PM
Post: #22
RE: Which systems support a COMPLEX data type?
(07-19-2023 12:24 AM)FLISZT Wrote:  In R language:

Code:

a <- sqrt(-1 + 0i)            # sqrt(-1) doesn't work → Warning message: In sqrt(-1) : NaNs produced
...

That's pretty cool, and now you've added one more language to my "must learn" list!

Interesting that it's not smart enough to realize that -1 = (-1 + 0i).

Reminds me of how painful it is on the HP-35s to get sqrt(-1). There, you cannot even compute sqrt(-1 + 0i). You have to compute (-1 + 0i) ^ 0.5. That's just dain brammaged.

Daily drivers: 15c, 32sII, 35s, 41cx, 48g, WP 34s/31s. Favorite: 16c.
Latest: 15ce, 48s, 50g. Gateway drug: 28s found in yard sale ~2009.
Find all posts by this user
Quote this message in a reply
07-19-2023, 03:30 PM
Post: #23
RE: Which systems support a COMPLEX data type?
(07-19-2023 02:14 PM)johnb Wrote:  Interesting that it's not smart enough to realize that -1 = (-1 + 0i).

In Python we get:

In [1]: from cmath import sqrt, exp, pi

In [2]: -1 == -1 + 0j
Out[2]: True

In [3]: sqrt(-1)
Out[3]: 1j

In [4]: exp(pi * 1j) + 1
Out[4]: 1.2246467991473532e-16j
Find all posts by this user
Quote this message in a reply
07-19-2023, 06:23 PM
Post: #24
RE: Which systems support a COMPLEX data type?
(07-19-2023 02:14 PM)johnb Wrote:  
(07-19-2023 12:24 AM)FLISZT Wrote:  In R language:

Code:

a <- sqrt(-1 + 0i)            # sqrt(-1) doesn't work → Warning message: In sqrt(-1) : NaNs produced
...

(…)
Interesting that it's not smart enough to realize that -1 = (-1 + 0i).
(…)

It reminds me of the hp-15C: flag No.8 has to be set (SF 8) to handle complex numbers.
I don't know a lot about the hp-35S, but I do know that a vintage hp-28 can compute the square root of -1, (-1 0) or '-1±0*i' directly and effortless. Smile
As the expression '-1±0*i' is enclosed in quotation marks, →NUM will be necessary to get a numerical value.
In all cases, the result will be of the form (n, m) ⇒ (0, -1).

While the R language can handle complex numbers (without the need of libraries), it is certainly not the most appropriate for an engineer.
It's better suited to a statistician, a data analyst (also Python), etc.

Bruno
Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G
Find all posts by this user
Quote this message in a reply
07-19-2023, 07:06 PM (This post was last modified: 07-19-2023 07:07 PM by HP67.)
Post: #25
RE: Which systems support a COMPLEX data type?
(07-12-2023 07:52 AM)Martin Hepperle Wrote:  In some languages like HP BASIC or Fortran, I can simply change the type from REAL to COMPLEX and no additional code changes are required.

I don't know if that's an HP (DEC / COMPAQ) Fortran extension, but it looks like (as of yet unverified) that FORTRAN IV had a COMPLEX type that would require function calls to convert to REAL. If so, changing the type could require code changes. And, it almost certainly would require code changes if calls were made to assembler subroutines as they often were.

When I get time I'll check this on various versions of IBM FORTRAN and some other compilers I have on various boxes (Sun Studio for SPARC, Intel for Intel/AMD). I had an emulated VMS box but I'm not sure the licenses are valid. That's a good system to look at the behavior of early DEC languages.

Anyway, interesting discussion!

It ain't OVER 'till it's 2 PICK
Find all posts by this user
Quote this message in a reply
07-19-2023, 07:50 PM
Post: #26
RE: Which systems support a COMPLEX data type?
(07-11-2023 09:42 AM)Martin Hepperle Wrote:  Which calculators or computers and computer languages support the Complex type?

(Here, I define "support" as a notation like C1=C2*C3, not by specific functions like C1=CPXMUL(C2,C3), and also including common trig and log functions)

I am aware of
  • HP 15C
  • HP32S, HP32SII
  • HP35S
  • HP42S
  • HP 71B Math ROM / BASIC
  • HP RPL in the HP 48/49 family
  • Fortran
  • HP 9000/200/300 Basic 5.x
  • C++ can model a Complex type (with operator overloading, so any language with operator overloading should be able to model it, bot it is not built into the language)
  • Some CASIO calculators, as discussed here.

I am sure there are a few more.

Martin
Quaternion HP41? https://www.hpmuseum.org/software/41/41quater.htm
I have made (no publication) some programs for quaternion algebra (indirect indexing; the link is with direct indexing). If need, I have to review and submit.

HP71 4TH/ASM & Multimod, HP41CV/X & Nov64d, PILBOX, HP-IL 821.62A & 64A & 66A, Deb11 64b-PC & PI2 3 4 w/ ILPER, VIDEO80, V41 & EMU71, DM41X, HP75D
Find all posts by this user
Quote this message in a reply
07-20-2023, 12:07 AM
Post: #27
RE: Which systems support a COMPLEX data type?
(07-19-2023 06:23 PM)FLISZT Wrote:  It reminds me of the hp-15C: flag No.8 has to be set (SF 8) to handle complex numbers.
I don't know a lot about the hp-35S, but I do know that a vintage hp-28 can compute the square root of -1, (-1 0) or '-1±0*i' directly and effortless. Smile

Yup, both the 28c and 28s. Also the 48sx, 48g/gx.
Generally, if I know I need complex numbers, I reach for my 48g. So much easier.

(07-19-2023 06:23 PM)FLISZT Wrote:  While the R language can handle complex numbers (without the need of libraries), it is certainly not the most appropriate for an engineer.
It's better suited to a statistician, a data analyst (also Python), etc.

Well, as a software engineer with a strong science background, I've found myself straddling a number of different disciplines at different times during my career. Maybe I'm weird even for an engineer?

Hm.

Well, actually, I already know that I am, because I'm strongly right-brained. I generally have flashes of random insight and then have to work backwards to connect the dots to turn it into proper engineering.

Daily drivers: 15c, 32sII, 35s, 41cx, 48g, WP 34s/31s. Favorite: 16c.
Latest: 15ce, 48s, 50g. Gateway drug: 28s found in yard sale ~2009.
Find all posts by this user
Quote this message in a reply
07-20-2023, 05:08 PM
Post: #28
RE: Which systems support a COMPLEX data type?
(07-20-2023 12:07 AM)johnb Wrote:  
(07-19-2023 06:23 PM)FLISZT Wrote:  It reminds me of the hp-15C: flag No.8 has to be set (SF 8) to handle complex numbers.
I don't know a lot about the hp-35S, but I do know that a vintage hp-28 can compute the square root of -1, (-1 0) or '-1±0*i' directly and effortless. Smile

Yup, both the 28c and 28s. Also the 48sx, 48g/gx.
Generally, if I know I need complex numbers, I reach for my 48g. So much easier.

(07-19-2023 06:23 PM)FLISZT Wrote:  While the R language can handle complex numbers (without the need of libraries), it is certainly not the most appropriate for an engineer.
It's better suited to a statistician, a data analyst (also Python), etc.

Well, as a software engineer with a strong science background, I've found myself straddling a number of different disciplines at different times during my career. Maybe I'm weird even for an engineer?

Hm.

Well, actually, I already know that I am, because I'm strongly right-brained. I generally have flashes of random insight and then have to work backwards to connect the dots to turn it into proper engineering.

I didn't notice that you have 2 RPL calculators (28s and 48g)!
Isn't weird?

It's true that stastics are not the prerogative of stasticians.
As far as I know, they are widely used in the world of science, among (many) others disciplines and industries.

Bruno
Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G
Find all posts by this user
Quote this message in a reply
Post Reply 




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