Code covered by the BSD License

### Highlights from Order of magnitude of number

5.0
5.0 | 6 ratings Rate this file 17 Downloads (last 30 days) File Size: 1.24 KB File ID: #28559 Version: 1.1

# Order of magnitude of number

### Ivar Eskerud Smith (view profile)

26 Aug 2010 (Updated )

Returns the order of magnitude of one or more numbers.

File Information
Description

Returns the order of magnitude of one or more numbers. Works on arrays. You can also specify the number base.

%Ex:
order( 1.2e-5 ) %returns -5
order(1) = 0
order( 1.12344e8 ) %returns 8
%Specify base 2:
order(1.2*2^5,2) %returns 5

Acknowledgements

Logb inspired this file.

This file inspired Seround: Round Value And Standard Error.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
02 Jun 2015 Ivar Eskerud Smith

### Ivar Eskerud Smith (view profile)

Joel, I seem to experience the same problem when the input is an exact integer value. I think this will be a problem when the input is a whole power of the base. I am not sure yet how this shuold be solved, one would have to do a test on the input to detect if it is a whole power of the base within numerical precision

Comment only
29 May 2015 Joel

### Joel (view profile)

I seem to experience a severe precision error using this function. I get order(1000) = 2. order(1000.000000000001) gives me the correct value of 3.

Comment only
25 May 2015 Irem Altan

### Irem Altan (view profile)

17 Jul 2012 Carlos

### Carlos (view profile)

Thanks!

09 Jun 2012 Ndilokelwa Luis

Efficient.

04 Apr 2012 John

### John (view profile)

I see what you're doing and it makes sense, thanks for the reply!

04 Apr 2012 Ivar Eskerud Smith

### Ivar Eskerud Smith (view profile)

Thanks John. But I think one should leave the order of magnitude of 0 to be minus infinity, that`s just what it is. If you set it to zero, consider this:
x=0;
o = order(x);
x2=10^o;
x2 and x should then be the same, but they won`t be if you set the order to 0. x2 would then be 1.

Comment only
03 Apr 2012 John

### John (view profile)

added the following to the bottom:

% If the value is zero then the order is set to zero
n(isinf(n)) = 0;

03 Apr 2012 John

works great!