How can I estimate the exponent of the Floating Point Arithmetic representation of a decimal number?

67 Views Asked by At

I am dealing with sums and substractions of large and small numbers in Matlab and I would like to estimate the exponent $e$ of the representation of the number in the computer which is in the form

$x = (-1)^{s} 2^e \ 1.f,$

in order to estimate the rounding error commited while storing it without having to manually pass it to binary representation.

1

There are 1 best solutions below

0
On

Excerpt of facts from https://mathworks.com/help/matlab/ref/log2.html

[F,E] = log2(X)

returns a pair of real and integer number (or arrays of it if X is an array)

For real X, the pair E,F satisfies the equation X = F.*2.^E. E is integer, F real, usually in the range 0.5 <= abs(F) < 1.

This function corresponds to the ANSI® C function frexp() and the IEEE floating-point standard function logb().


Note however that as (1.ddd)_2 = 2 * (0.1ddd)_2, the result you are looking for is E-1. (Which may be irrelevant, as you want to compare sizes.)