Reputation: 1209
How do we extract the exponent and sign from a "scientific" notation?
If we print a double value with printf("%lf %e") it shows par ex.:
normal scientific
------ ----------
-888.3 -8.88e2
1.23 1.23e0
3.001 3.1e-1
The solution pointed in How to get Exponent of Scientific Notation in Matlab
x = floor(log10(N))
works only for positive values N. With -N it shows -nan(ind). Obviously Log10() with negatie value is not allowed.
Upvotes: 0
Views: 1176
Reputation: 44838
You don't care about the sign of the number, you need the exponent only, so you can get rid of the sign safely:
log10(abs(N))
Where abs
returns the absolute value of N
, which is always non-negative and thus can be used as an argument to log10
.
Upvotes: 2