Complex numbers not in fundamental class?

조회 수: 4 (최근 30일)
Mohammed Hamaidi
Mohammed Hamaidi 2022년 3월 21일
답변: Walter Roberson 2022년 3월 21일
Hi Community
Since a complex number is 1x1 array, why isn't in fundamental class type of datas?

채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 21일
Observe
format long g
t = complex(single(3), single(-5)), whos t
t = single
3 - 5i
Name Size Bytes Class Attributes t 1x1 8 single complex
t = complex(double(3), double(-5)), whos t
t =
3 - 5i
Name Size Bytes Class Attributes t 1x1 16 double complex
t = complex(int8(3), int8(-5)), whos t
t = int8
3 - 5i
Name Size Bytes Class Attributes t 1x1 2 int8 complex
t = complex(uint64(3), uint64(5))
t = uint64
3 + 5i
Complex is an attribute, not a class. If you made it a class, you would need a separate class for each different datatype that can be complex -- single, double, int8, uint8, int16, uint16, int32, uint32, int64, uint64. (Complex logical and complex char get converted to double precision.)
Meanwhile you would still need isnumeric() and issingle() and isdouble() and isinteger() to continue to work on the values. What would your inheritence hierarchy be?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by