numeric::complexRound
--
round a complex number towards the real or imaginary axisnumeric::complexRound
(z, ..)
discards
small real or imaginary parts of complex floating point numbers
z
.
numeric::complexRound(z <, eps>)
|
- | an arbitrary MuPAD object |
|
- | a real number >= 10^(-DIGITS). |
If z
is a complex floating point number, then a real or
complex floating point number is returned. For all other types
z
is returned unchanged.
The function is sensitive to the environment variable DIGITS
.
ceil
, floor
, frac
, round
, trunc
z
satisfies
Re(z)<eps*abs(z)
, then it is replaced by zero and
Im(z)*I
is returned.
If the imaginary part of z
satisfies
Im(z)<eps*abs(z)
, then it is replaced by zero and
Re(z)
is returned.
eps
=10^(-DIGITS) this
rounding changes a complex floating point number by less than the
relative standard precision.numeric::fsolve
, numeric::polyroots
, numeric::polysysroots
and
numeric::sum
.eps
eps
=10^(-DIGITS).eps
>=10^(-DIGITS) are
accepted.PI*sqrt(2)/10^10
etc.
are accepted and converted to floats.Exact numbers are not changed:
>> numeric::complexRound(2 + I/10^20)
2 + 1/100000000000000000000 I
Also the following number has an exact imaginary part and is not rounded:
>> numeric::complexRound(2.0 + sqrt(2)*I/10^20)
1/2 1/100000000000000000000 I 2 + 2.0
Rounding occurs for complex floats, if this does not change its value significantly:
>> numeric::complexRound(1.0 + 2.0*I/10^10), numeric::complexRound(1.0 + 2.0*I/10^11)
1.0 + 0.0000000002 I, 1.0
Note that rounding is based on relative precision, i.e., only the ratio of real and imaginary parts is relevant:
>> numeric::complexRound((1.0 + 2.0*I)/10^100)
10.0e-101 + 2.0e-100 I
>> numeric::complexRound((1.0 + 1.0/10^11*I)/10^100)
10.0e-101
The relative precision for rounding may be reduced by
the optional parameter eps
:
>> numeric::complexRound(2.0/10^10 + I), numeric::complexRound(2.0/10^10 + I, PI/10^5)
0.0000000002 + 1.0 I, 1.0 I