L
Luna Moon
Hi all,
I am using Matlab 2007a and MSVS.NET2003 on Windows XP.
I used Matlab for prototyping and now I converted the code line by
line into C++.
However, there was some precision issue with my C++ results.
I suspected that I didn't understand the numerical difference between
Matlab and C++ correctly.
Specifically, I don't really know how to translate the following two
Matlab expressions, and what are their equivalent statements in C++?
Here I attached a few examples and their Matlab documents. Could you
please help me? Thanks!
ans =
1.1755e-038
ans =
2.2251e-308
REALMIN Smallest positive floating point number.
x = realmin is the smallest positive normalized double precision
floating
point number on this computer. Anything smaller underflows or is
an IEEE
"denormal".
REALMIN('double') is the same as REALMIN with no arguments.
REALMIN('single') is the smallest positive normalized single
precision
floating point number on this computer.
See also eps, realmax, intmin.
Reference page in Help browser
doc realmin
------------------------
ans =
2.2204e-016
ans =
1.1369e-013
EPS Spacing of floating point numbers.
D = EPS(X), is the positive distance from ABS(X) to the next
larger in
magnitude floating point number of the same precision as X.
X may be either double precision or single precision.
For all X, EPS(X) is equal to EPS(ABS(X)).
EPS, with no arguments, is the distance from 1.0 to the next
larger double
precision number, that is EPS with no arguments returns 2^(-52).
EPS('double') is the same as EPS, or EPS(1.0).
EPS('single') is the same as EPS(single(1.0)), or single(2^-23).
Except for numbers whose absolute value is smaller than REALMIN,
if 2^E <= ABS(X) < 2^(E+1), then
EPS(X) returns 2^(E-23) if ISA(X,'single')
EPS(X) returns 2^(E-52) if ISA(X,'double')
For all X of class double such that ABS(X) <= REALMIN, EPS(X)
returns 2^(-1074). Similarly, for all X of class single such
that
ABS(X) <= REALMIN('single'), EPS(X) returns 2^(-149).
Replace expressions of the form
if Y < EPS * ABS(X)
with
if Y < EPS(X)
Example return values from calling EPS with various inputs are
presented in the table below:
Expression Return Value
===========================================
eps(1/2) 2^(-53)
eps(1) 2^(-52)
eps(2) 2^(-51)
eps(realmax) 2^971
eps(0) 2^(-1074)
eps(realmin/2) 2^(-1074)
eps(realmin/16) 2^(-1074)
eps(Inf) NaN
eps(NaN) NaN
-------------------------------------------
eps(single(1/2)) 2^(-24)
eps(single(1)) 2^(-23)
eps(single(2)) 2^(-22)
eps(realmax('single')) 2^104
eps(single(0)) 2^(-149)
eps(realmin('single')/2) 2^(-149)
eps(realmin('single')/16) 2^(-149)
eps(single(Inf)) single(NaN)
eps(single(NaN)) single(NaN)
See also realmax, realmin.
Reference page in Help browser
doc eps
I am using Matlab 2007a and MSVS.NET2003 on Windows XP.
I used Matlab for prototyping and now I converted the code line by
line into C++.
However, there was some precision issue with my C++ results.
I suspected that I didn't understand the numerical difference between
Matlab and C++ correctly.
Specifically, I don't really know how to translate the following two
Matlab expressions, and what are their equivalent statements in C++?
Here I attached a few examples and their Matlab documents. Could you
please help me? Thanks!
ans =
1.1755e-038
ans =
2.2251e-308
REALMIN Smallest positive floating point number.
x = realmin is the smallest positive normalized double precision
floating
point number on this computer. Anything smaller underflows or is
an IEEE
"denormal".
REALMIN('double') is the same as REALMIN with no arguments.
REALMIN('single') is the smallest positive normalized single
precision
floating point number on this computer.
See also eps, realmax, intmin.
Reference page in Help browser
doc realmin
------------------------
ans =
2.2204e-016
ans =
1.1369e-013
EPS Spacing of floating point numbers.
D = EPS(X), is the positive distance from ABS(X) to the next
larger in
magnitude floating point number of the same precision as X.
X may be either double precision or single precision.
For all X, EPS(X) is equal to EPS(ABS(X)).
EPS, with no arguments, is the distance from 1.0 to the next
larger double
precision number, that is EPS with no arguments returns 2^(-52).
EPS('double') is the same as EPS, or EPS(1.0).
EPS('single') is the same as EPS(single(1.0)), or single(2^-23).
Except for numbers whose absolute value is smaller than REALMIN,
if 2^E <= ABS(X) < 2^(E+1), then
EPS(X) returns 2^(E-23) if ISA(X,'single')
EPS(X) returns 2^(E-52) if ISA(X,'double')
For all X of class double such that ABS(X) <= REALMIN, EPS(X)
returns 2^(-1074). Similarly, for all X of class single such
that
ABS(X) <= REALMIN('single'), EPS(X) returns 2^(-149).
Replace expressions of the form
if Y < EPS * ABS(X)
with
if Y < EPS(X)
Example return values from calling EPS with various inputs are
presented in the table below:
Expression Return Value
===========================================
eps(1/2) 2^(-53)
eps(1) 2^(-52)
eps(2) 2^(-51)
eps(realmax) 2^971
eps(0) 2^(-1074)
eps(realmin/2) 2^(-1074)
eps(realmin/16) 2^(-1074)
eps(Inf) NaN
eps(NaN) NaN
-------------------------------------------
eps(single(1/2)) 2^(-24)
eps(single(1)) 2^(-23)
eps(single(2)) 2^(-22)
eps(realmax('single')) 2^104
eps(single(0)) 2^(-149)
eps(realmin('single')/2) 2^(-149)
eps(realmin('single')/16) 2^(-149)
eps(single(Inf)) single(NaN)
eps(single(NaN)) single(NaN)
See also realmax, realmin.
Reference page in Help browser
doc eps