0

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.

Community
  • 1
  • 1
Tom Tom
  • 1,127
  • 11
  • 25

1 Answers1

2

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.

ForceBru
  • 43,482
  • 10
  • 63
  • 98